﻿@using LanDBom.Models;
@using LanDBom.Resources
@{
    ViewBag.Title = "Application";
}
@section styles{
    <style>
        .huns {
            text-decoration-line: underline;
            color: red;
            border: none;
        }

        .YCFile {
            display: none;
            background-color: #fff;
            width: 350px;
            height: 150px;
            position: absolute;
            left: 22%;
            top: 40%;
        }

        .YANds {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: #0866a563;
            border-radius: 8px;
            margin: 3px 4px;
            padding: 2px 10px;
        }

        .SHnacs {
            display: flex;
            width: 96%;
            height: 65%;
            align-items: flex-start;
            justify-content: space-between;
            background-color: #cecece;
            border-radius: 8px;
            margin: 3px 4px;
            padding: 2px 10px;
        }

        span {
            color: red
        }

        #APP_sjwt_bz div {
            width: 100%;
            margin-left: 20px;
        }

        #APP_sjwt_bz {
            width: 97%;
            margin-bottom: 10px;
        }

        .qh_div {
            text-align: center
        }
    </style>
}
<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item ">ERP物料创建</label>
            <ul id="lisul" class="row col-sm-5">
                <li style="font-size:20px;color:red"> <b>输入框显示红色表示该物料已存在</b> </li>
            </ul>

            <div class="col-sm-4">
                <div class="anzhu" style="text-align:right">
                    <div class="col-2" id="divv_2"><button id="btnBaocun" class="btn_app_tj Yinchande" type="button" value="保存">保存</button></div>
                    <div class="col-2" id="divv_1"><button id="btnCreate" class="btn_app_tj" type="button" value="提交">提交</button></div>
                    @*<div class="col-2" style="display:none" id="divv_09"><button id="btnUpdate" type="button" value="修改">修改设计委托</button></div>*@
                    @*<div class="col-2" style="display:none" id="divv_4"><button id="btnBOHUI" type="button">驳回</button></div>*@
                    @*<div class="col-2" style="display:none" id="divv_8"><button id="btnWCXM" type="button">通过</button></div>*@
                    @*<div class="col-2" style="display:none" id="divv_6"><button id="WCSJ" type="button">递交</button></div>*@
                    @*<div class="col-2" style="display:none" id="divv_5"><button id="btnWANC" type="button">完成设计</button></div>*@
                    <div class="col-2" id="divv_3"><button id="btnreste" type="button">返回</button></div>
                </div>
            </div>

        </div>
    </fieldset>
</from>
<div class="form-horizontal row">
    <div style="display:none" id="LIunji">@ViewBag.Shuai</div>

    <div id="appp_id" style="display:none">@(Session["appp_id"])</div>
    <div id="appp_Sjzt" style="display:none">@(Session["name"])</div>

    <div class="col-12">
        <fieldset class="boun">
            <legend class="len">单据信息</legend>
            <table class="table-app" cellpadding="2" align="left">
                <tr>
                    <td class="form-group">
                        <label for="CL_number" class=" control-label">单据编码</label>
                    </td>
                    <td><input type="text" class="form-control" id="txtdan" placeholder="名称" name="dan" readonly="readonly"></td>
                    <td class="form-group">
                        <label for="CL_number" class=" control-label">创建人</label>
                    </td>
                    <td><input type="text" class="form-control" id="CJR" placeholder="名称" name="dan" readonly="readonly"></td>
                </tr>
            </table>
        </fieldset>
    </div>
    @*BOM模块*@
    <div class="col-12" data-spy="scroll" data-target="#navbar-example2" data-offset="0" id="APP_WLSQ">
        <fieldset class="boun">
            <legend class="len">@Resource.String90</legend>
            <div class="row Yinchande" id="shshj">
                @*<div class="col-2" id="xinzengWL">新增物料</div>*@
                <div class="col-2" id="addwl">@Resource.String91</div>
                @*<div class="col-2" id="Tiao">@Resource.String92</div>*@
                <div class="col-2" id="DELcheck">@Resource.String93</div>
            </div>
            <div>
                <div style="display:none" id="JINDN">
                    @* <lable id="XINzhengWL" style="color: blue; border-bottom: 1px solid blue; ">@Resource.String94</lable>*@
                    <lable style="color: blue; border-bottom: 1px solid blue;" id="xinzengWL">@Resource.String2001</lable>
                </div>
                <div id="Yin" style="display:none">
                    <a href="/Material/Ecssxsdd?shu=1" id="Xiaxz" style="color: blue; border-bottom: 1px solid blue; ">@Resource.String96</a>
                    <a style="color: blue; border-bottom: 1px solid blue;" id="ShangC">@Resource.String97</a>
                </div>
            </div>

            <div>
                <table class="table tab">
                    <thead style="text-align:center;">
                        <tr style="background-color: #6e95bc">
                            <th scope="col" style="width:20px;"><input type="checkbox" id="QXK" /></th>
                            <th scope="col">@Resource.String98</th>
                            <th scope="col">@Resource.String100</th>
                            <th scope="col">@Resource.String99</th> @*料号*@
                            <th scope="col" style="width: 200px;">物料名</th> @*名字*@
                            <th scope="col">@Resource.String101</th>
                            <th scope="col">@Resource.String102</th>
                            <th scope="col">@Resource.String103</th>
                            <th scope="col">@Resource.String104</th>
                            <th scope="col">@Resource.String105</th>
                            <th scope="col">@Resource.String106</th>
                            <th scope="col">@Resource.String107</th>
                        </tr>
                    </thead>
                    @using (Html.BeginForm("AddAppli", "Application", FormMethod.Post))
                    {
                        <tbody data-spy="scroll" id="WLTable" style="background-color: #fff; max-height: 500px; height: 500px">
                        </tbody>
                    }
                </table>
            </div>
        </fieldset>
    </div>
    @*BOM上传面板*@
    <div class="YCFile">
        <div class="YANds"><span>@Resource.String108</span><span><i class="bi bi-x-circle-fill" id="Quxiao"></i></span></div>
        <div class="SHnacs">
            <input type="file" value="" id="SHanngcF" accept="" />
            <input type="button" value="@Resource.String108" id="TIjaio" />
        </div>
    </div>
    @*新建物料和料号*@
    <div id="addwl_main" style="display: none; position: absolute; border: 1px black solid; left: 20%; top: 30%; background-color: white; background-color: #f1f1f1">
        <div style="text-align: right; background-color: #84acde;" class="Tuodong">点击这里拖动窗体<span class="quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <table id="addwl_main_tab">
                <tr><td style="color:red">@Resource.String1261</td></tr>
                <tr><td>层级</td><td><select id="LevenED"><option value="Leve0">Leve0</option><option value="leve1">leve1</option><option value="leve2">leve2</option></select></td></tr>
                <tr>
                    <td>@Resource.String512<span style="color:red">*</span></td>
                    <td><input type="text" id="amt_WLM" class="amt_v" /></td>
                    <td>@Resource.String111</td>
                    @*料号*@
                    <td><input type="text" id="amt_WLBM" class="" readonly /></td>
                </tr>
                <tr>
                    <td>@Resource.String112</td>
                    <td><input type="number" id="amt_NYL" class="amt_v" /></td>
                    <td>@Resource.String113</td>
                    <td>
                        <input type="text" name="Biaomian" value="" readonly />
                        <div style="display:none" id="Yinchangs" class="Dingdiv">
                            <div style="display: flex; justify-content: space-between;"><span id="TanT">添加</span> <span><i class="bi bi-x-circle-fill quxiaoshi"></i></span></div>
                            <ul style="height:100px;overflow-y:scroll" id="ULAP">
                                @foreach (var item in ViewBag.ZUI as List<jectsche>)
                                {
                                    <li><input type="checkbox" value="@item.Je_hanghao" class="Xuanz" />@item.Je_hanghao</li>
                                }
                            </ul>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>@Resource.String114</td>
                    <td><input type="text" id="amt_BMCL" class="amt_v" /></td>
                    <td>@Resource.String115</td>
                    <td><input type="text" id="amt_YCL" class="amt_v" /></td>
                </tr>
                <tr>
                    <td>@Resource.String116 <span style="color:red">*</span></td>
                    <td>
                        <select id="dl_wl" class="form-control">
                            <option value="0">请选择</option>
                            @foreach (var item in ViewBag.temp2 as List<buty3>)
                            {
                                <option value="@item.zl2_id">@item.zl2_name</option>
                            }
                        </select>
                    </td>
                    <td>@Resource.String120<span style="color:red">*</span></td>
                    <td>
                        <select class="form-control" id="leibei_x" placeholder="">
                            <option value="彩印纸箱">@Resource.String121</option>
                            <option value="水印拉链箱">@Resource.String1305</option>
                            <option value="水印瓦楞箱">@Resource.String1304</option>
                            <option value="瓦楞平板（规格≥500*250）">@Resource.String1306</option>
                            <option value="标签">@Resource.String1308</option>
                            <option value="说明书/卡片/折页">@Resource.String1309</option>
                            <option value="纸">@Resource.String1310</option>
                            <option value="纸护角">@Resource.String1311</option>
                            <option value="纸管">@Resource.String1312</option>
                            <option value="蜂窝制品">@Resource.String1313</option>
                            <option value="纸托盘">@Resource.String1314</option>
                            <option value="纸塑">@Resource.String1315</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>@Resource.String123 (mm)<span style="color:red">*</span></td>
                    <td><input type="number" class="amt_v guig" id="cahns" /></td>
                    <td>*<input type="number" class="amt_v guig" id="cahns1" /></td>
                    <td>*<input type="number" class="amt_v guig" id="cahns2" /></td>
                </tr>
                <tr>
                    <td>@Resource.String124</td>
                    <td><input type="text" id="amt_MS" class="amt_v" /></td>
                    <td>计量单位<span style="color:red">*</span></td>
                    <td>
                        <select id="amt_DW" style="width:100px;">
                            @foreach (var item in ViewBag.JIliang as List<Freht>)
                            {
                                <option value="@item.Fre_shijian">@item.Fre_beizhu</option>
                            }
                        </select>
                    </td>
                </tr>
                <tr><td>自制或外购</td><td><select id="shuxinss" style="width:100px;"><option value=""></option><option value="外购">外购</option><option value="自制">自制</option></select></td></tr>
            </table>
            <table class="table">
                <thead style="text-align:center;">
                    <tr style="background-color: #6e95bc">
                        <th>序号</th>
                        <th>文件名</th>
                        <th>料号</th>
                        <th>上传人</th>
                        <th>上传</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
                <tfoot>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><a id="show_shgcdiv">上传</a></td>
                    </tr>
                </tfoot>
            </table>
        </div>
        <div style=" display: flex; justify-content: center;"><button id="queding">@Resource.String125</button>&emsp;&emsp;<button class="quxiao">@Resource.String126</button></div>
    </div>

    @*添加起订量*@
    <div id="addwl_main" class="ZUIXIAO" style="display: none; position: absolute; border: 1px black solid; left: 32%; top: 43%; background-color: white; background-color: #f1f1f1">
        <div style="text-align: right; background-color: #84acde;">最小起订量添加<span class="shhhudb" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <input type="text" value="" class="HNFJI" />
        </div>
        <div style=" display: flex; justify-content: center;"><button id="JInRU">@Resource.String125</button>&emsp;&emsp;<button class="KOHUS">@Resource.String126</button></div>
    </div>
    @*设计图提交面板*@
    <div id="show_shangc" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1">
        <div style="text-align: right; background-color: #84acde;" class="Tuodong"><span class="QUED_quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <div><span>请输入设计用时</span><input type="number" id="SLong" /></div>
            <p></p>
            <div><input type="file" id="SCWJ_SJ" /></div>
            <table>
                <tr>
                    <td class="form-group">
                        <label for="CL_email" class=" control-label">@Resource.String80</label>
                    </td>
                    <td class="">
                        <select class="form-control" id="SJ_HANG1" placeholder="行业大类" name="hangye1">
                            <option value="">--@Resource.String48--</option>
                            @foreach (var item in ViewBag.ic as List<IndustryCategory>)
                            {
                                <option value="@item.ic_id" id="CL_ID">@item.ic_name</option>
                            }
                        </select>
                    </td>
                    <td class="form-group">
                        <label for="CL_email" class=" control-label">@Resource.String81</label>
                    </td>
                    <td class="">
                        <select class="form-control" id="SJ_HANG2" placeholder="行业小类" name="hangye2">
                            <option value="">--@Resource.String63--</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="form-group">
                        <label for="CL_email" class=" control-label">包装品类</label>
                    </td>
                    <td class="">
                        <select class="form-control" id="TZ_BZPL" placeholder="包装品类" name="hangye1">
                            <option value="0">--@Resource.String48--</option>
                            <option value="纸质产品">纸质产品</option>
                            <option value="木制品">木制品</option>
                            <option value="塑料制品">塑料制品</option>
                            <option value="泡沫防护产品">泡沫防护产品</option>
                            <option value="可回收的">可回收的</option>
                            <option value="包装配件">包装配件</option>
                            <option value="多种材质">多种材质</option>
                            <option value="其他">其他</option>
                        </select>
                    </td>
                    <td class="form-group">
                        <label for="CL_email" class=" control-label">图纸类别</label>
                    </td>
                    <td class="">
                        <select class="form-control" id="TZ_TZLB" placeholder="图纸类别" name="hangye2">
                            <option value="0">--@Resource.String48--</option>
                            <option value="结构图">结构图</option>
                            <option value="印刷图">印刷图</option>
                            <option value="套件">套件</option>
                            <option value="SOP(操作指导）">SOP(操作指导）</option>
                            <option value="测试报告">测试报告</option>
                            <option value="其他">其他</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="form-group">
                        <label for="CL_email" class=" control-label">@Resource.String82</label>
                    </td>
                    <td class="">
                        <input type="text" class="form-control" id="SJ_bzwmc" placeholder="包装物名称" name="zhongduan">
                    </td>
                </tr>
            </table>
        </div>
        <div style="text-align:center"><button id="QUEding_SC">@Resource.String125</button>&emsp;&emsp;<button class="QUED_quxiao">@Resource.String126</button></div>
    </div>

    @*设计图驳回面板*@
    <div id="WT_dh_mb" style="display:none;position:fixed;background-color:white;top:200px;width:660px;left:300px;z-index:1000;border:1px black solid;">
        <div id="WJ_ID" style="display:none"></div>
        <div id="WJ_tjr" style="display:none"></div>
        <table>
            <tr>
                <td>@Resource.String548：</td>
                <td id="WT_dhr"></td>
            </tr>
            <tr>
                <td>@Resource.String549</td>
                <td><textarea id="WT_dhly"></textarea></td>
            </tr>
            <tr>
                <td id="WT_qdbh">@Resource.String550</td>
                <td id="WT_qxbh">@Resource.String551</td>
            </tr>
        </table>
    </div>

    <div id="WT_dh_mb2" style="display:none;position:fixed;background-color:white;top:200px;width:660px;left:300px;z-index:1000;border:1px black solid;">
        <table>
            <tr>
                <td>@Resource.String632：</td>
                <td id="WT_dhr2"></td>
            </tr>
            <tr>
                <td>@Resource.String633</td>
                <td><textarea id="WT_dhly2"></textarea></td>
            </tr>
            <tr>
                <td id="WT_qdbh2">@Resource.String634</td>
                <td id="WT_qxbh2">@Resource.String635</td>
            </tr>
        </table>
    </div>

    <div id="WT_dh_mb3" style="display:none;position:fixed;background-color:white;top:200px;width:660px;left:300px;z-index:1000;border:1px black solid;">
        <table>
            <tr>
                <td>@Resource.String548：</td>
                <td id="WT_dhr3"></td>
            </tr>
            <tr>
                <td>@Resource.String549</td>
                <td><textarea id="WT_dhly3"></textarea></td>
            </tr>
            <tr>
                <td id="WT_qxbh3">@Resource.String551</td>
            </tr>
        </table>
    </div>
</div>


<div style="display:none" id="DE_ID_1">0</div>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            var namd = $("#appp_Sjzt").text()
            $("#lihfh").css({ "color": "black", "background-color": "white" })

            $("input,select").attr({ "autocomplete": "off"})
            var amsndol = $("#Login_N").text()
            $("#WT_sqr").val(amsndol)
            Liaohao()//料号编号
            $(".shhhudb,.KOHUS").click(function () {
                $(".ZUIXIAO").hide()
            })
            $(document).on("click", "#Selse", function (e) {
                var index = $(e.target).val()
                if (index == "Y" || index == "S") {
                    $("#divweituo").css({ "display": "block" })
                }
                else {
                    $("#divweituo").css({ "display": "none" })
                }
            })
            $("#TanT").click(function () {
                $(".ZUIXIAO").show()
            })
            $("#QXK").click(function () {
                if ($("#QXK").prop("checked") == true) {
                    console.log(1)
                    $(".XANZK").prop("checked", true)
                }
                else {
                    $(".XANZK").prop("checked", false)
                }
            })
            //点击打开上传文件
            $(document).on("click", "#show_shgcdiv", function (e) {
                $("#show_shangc").css({ "display": "block" })
                $("#DE_ID_1").text(0)
            })
            //点击图纸重新上传
           /* $(document).on("click", "#log_SXSC", function (e) {
                var id = $(e.target).parent().parent().children().eq(0).text()
                var temp = $(e.target).parent().parent().children().eq(5).text()
                if (temp == $("#Login_N").text()) {
                    $.ajax({
                        url: '/Contracts/Inspect_Contracts',
                        type: 'GET',
                        data: { "state": 3, "D_ID": $("#Login_name").text(), "D_Ton": $("#txtdan").val() },
                        success: function (zc) {
                            $.each(zc, function (i, obj) {
                                if (obj.SJ_ZT == "完成") {
                                    alert("已递交，无法删除")
                                }
                                else {
                                    $("#show_shangc").css({ "display": "block" })
                                    $("#DE_ID_1").text(id)
                                }
                            })
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })

                }
                else if ($("#Login_sf").text() == "设计主管" || $("#Login_sf").text() == "设计经理") {
                    $("#DE_ID_1").text(id)

                }
                else {
                    alert("只有上传人和设计主管可以重新上传")
                }
            })*/
            $("#JInRU").click(function () {
                var shund = $(".HNFJI").val()
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 20, "husJI": shund },
                    success: function (path) {
                        alert(path)
                        if (path == "添加成功") {
                            var $LI = $(`<li><input type="checkbox" value="${shund}" class="Xuanz" />${shund}</li>`)
                            $("#ULAP").append($LI)
                        }
                        $(".ZUIXIAO").hide()
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            })
            //点击图纸删除
            $(document).on("click", "#log_SC", function (e) {

                var id = $(e.target).parent().parent().children().eq(0).text()
                var temp = $(e.target).parent().parent().children().eq(5).text()

                console.log(id)
                if (temp == $("#Login_N").text()) {
                    $.ajax({
                        url: '/Contracts/Inspect_Contracts',
                        type: 'GET',
                        data: { "state": 3, "D_ID": $("#Login_name").text(), "D_Ton": $("#txtdan").val() },
                        success: function (zc) {
                            $.each(zc, function (i, obj) {
                                if (obj.SJ_ZT == "完成") {
                                    alert("已递交，无法删除")
                                }
                                else {
                                    $.ajax({
                                        url: '/Application/Application',
                                        type: 'POST',
                                        data: { "state": 13, "id": id },
                                        success: function (path) {
                                            alert(path)
                                            Load_design_table()
                                        },
                                        error: function () {
                                            alert("系统错误!");
                                        }
                                    })
                                }
                            })
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }
                else if ($("#Login_sf").text() == "设计主管" || $("#Login_sf").text() == "设计经理") {
                    $.ajax({
                        url: '/Application/Application',
                        type: 'POST',
                        data: { "state": 13, "id": id },
                        success: function (path) {
                            alert(path)
                            Load_design_table()
                        },
                        error: function () {
                            alert("系统错误!");
                        }
                    })
                }
                else {
                    alert("只有上传人和设计主管可以删除")
                }

            })
            //关闭文件上传
            $(document).on("click", "#QUED_quxiao", function (e) {
                $("#show_shangc").css({ "display": "block" })
                $("#SCWJ_SJ").val("")
                $("#SLong").val("")
            })
            //点击上传文件
            $(document).on("click", "#QUEding_SC", function () {
                Upload_attachment()
            })
            //关闭文件上传
            $(document).on("click", ".QUED_quxiao", function () {
                $("#show_shangc").css({"display":"none"})
            })
            //上传项目附件
            $(document).on("click", "#log_SCFJ", function () {
                Upload_attachmentfujian()
            })
            //上传备注的方法
            $(document).on("click", "#RZ_tjrz", function () {
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var hours = (now.getHours()).toString()
                var minutes = (now.getMinutes()).toString()
                var name = $("#Login_N").text()
                //组合当前日期
                var sqrq = year + "-" + month + "-" + date + " " + hours + ":" + minutes
                var rzxx = {
                    B_Bian: $("#txtdan").val(),
                    B_BR: name,
                    B_Date: sqrq,
                    B_bei: $('#RZ_xznr').val(),

                };
                console.log(rzxx)
                $.ajax({
                    url: "/Contracts/AddLogs",
                    type: "POST",
                    data: rzxx,
                    success: function (data) {
                        gettbz()
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            })
            //上传附件
            function Upload_attachmentfujian() {
                var fileUpload = $('#SC_FJ_Wj')[0];
                if (fileUpload.files.length > 0) {
                    var fileData = new FormData();
                    fileData.append('file', fileUpload.files[0]);
                    var now = new Date($.now());
                    var year = (now.getFullYear()).toString();
                    var month = (now.getMonth() + 1).toString();
                    var date = (now.getDate()).toString();
                    var hours = (now.getHours()).toString()
                    var minutes = (now.getMinutes()).toString()
                    var name = $("#Login_N").text()
                    //组合当前日期
                    var sqrq = year + "-" + month + "-" + date + " " + hours + ":" + minutes
                    $.ajax({
                        url: "/Contracts/AddNdardo",
                        type: "POST",
                        contentType: false, // 不设置内容类型
                        processData: false, // 不处理数据
                        data: fileData,
                        success: function (response) {
                            var BZJG = [];
                            BZJG.push({
                                DE_dizhi: response,
                                DE_shijian: sqrq,
                                DE_shen: $("#txtdan").val(),
                                De_ren: name,
                                DE_lei: "附件"
                            })
                            console.log(BZJG)
                            $.ajax({
                                url: '/Contracts/adddes',
                                type: 'POST',
                                contentType: "application/json;charset=utf-8", // 不设置内容类型
                                dataType: "json",
                                processData: false, // 不处理数据
                                data: JSON.stringify(BZJG), fileData,
                                success: function (REson) {
                                    alert(REson)
                                    Load_design_table()
                                    $("#show_shangc").css({ "display": "none" })
                                },
                                error: function ( errorMessage) {
                                    alert('AJAX请求失败1：' + errorMessage);
                                }
                            });
                        },
                        error: function ( errorMessage) {
                            alert('AJAX请求失败：' + errorMessage);
                        }
                    });
                }
                else {
                    alert('请选择要上传的文件！');
                }

            }
            //上传设计图纸
            function Upload_attachment() {
                if (true) {
                    var id = $("#DE_ID_1").text()
                    var lei2 = null
                    if ($("#SJ_HANG1").val() != 0) {
                        lei2 = $("#SJ_HANG1").val()
                    }
                    var fileUpload = $('#SCWJ_SJ')[0];
                    if (fileUpload.files.length > 0) {
                        var fileData = new FormData();
                        fileData.append('file', fileUpload.files[0]);
                        console.log(fileData)
                        if ($("#SLong").val() != null) {
                            var now = new Date($.now());
                            var year = (now.getFullYear()).toString();
                            var month = (now.getMonth() + 1).toString();
                            var date = (now.getDate()).toString();
                            var hours = (now.getHours()).toString()
                            var minutes = (now.getMinutes()).toString()
                            var name = $("#Login_N").text()
                            var SLong = $("#SLong").val()
                            //组合当前日期
                            var sqrq = year + "-" + month + "-" + date + " " + hours + ":" + minutes
                            $.ajax({
                                url: '/Contracts/AddNdardo',
                                type: 'POST',
                                contentType: false, // 不设置内容类型
                                processData: false, // 不处理数据
                                data: fileData,
                                success: function (response) {
                                    var BZJG = [];
                                    if (id == 0) {
                                        BZJG.push({
                                            DE_dizhi: response,
                                            DE_shijian: sqrq,
                                            DE_shen: $("#txtdan").val(),
                                            De_ren: name,
                                            DE_Slong: SLong,
                                            DE_tuiLei: "待审核",
                                            bom_id: $("#amt_WLBM").val(),
                                            DE_lei: "图纸",
                                            DE_h1_id: $("#SJ_HANG1").val(),
                                            DE_h2_id: lei2,
                                            DE_bzpl: $("#TZ_BZPL").val(),
                                            DE_tzlb: $("#TZ_TZLB").val(),
                                            DE_bzw: $("#SJ_bzwmc").val(),
                                        })
                                    }
                                    else {
                                        BZJG.push({
                                            DE_id: id,
                                            DE_dizhi: response,
                                            DE_shijian: sqrq,
                                            DE_shen: $("#txtdan").val(),
                                            De_ren: name,
                                            DE_Slong: SLong,
                                            DE_tuiLei: "待审核",
                                            bom_id: $("#amt_WLBM").val(),
                                            DE_lei: "图纸",
                                            DE_h1_id: $("#SJ_HANG1").val(),
                                            DE_h2_id: $("#SJ_HANG2").val(),
                                            DE_bzpl: $("#TZ_BZPL").val(),
                                            DE_tzlb: $("#TZ_TZLB").val(),
                                            DE_bzw: $("#SJ_bzwmc").val(),
                                        })
                                    }
                                    console.log(BZJG)
                                    if ($("#SJ_HANG1").val() == "") {
                                        alert("必填项不能为空！")
                                    } else if ($("#SJ_HANG2").val() == null && $("#SJ_HANG2").val() == "") {
                                        alert("必填项不能为空！")
                                    } else if ($("#TZ_BZPL").val() == "") {
                                        alert("必填项不能为空！")
                                    } else if ($("#TZ_TZLB").val() == "") {
                                        alert("必填项不能为空！")
                                    } else if ($("#SJ_bzwmc").val() == "") {
                                        alert("必填项不能为空！")
                                    } else {
                                        $.ajax({
                                            url: '/Contracts/adddes',
                                            type: 'POST',
                                            contentType: "application/json;charset=utf-8", // 不设置内容类型
                                            dataType: "json",
                                            processData: false, // 不处理数据
                                            data: JSON.stringify(BZJG), fileData,
                                            success: function (response) {
                                                if (response == "") {
                                                    alert("文件上传失败")
                                                } else {
                                                    alert("文件上传成功")
                                                    Load_design_table()
                                                    $("#show_shangc").css({ "display": "none" })
                                                }

                                            },
                                            error: function (jqXHR, textStatus, errorMessage) {
                                                alert('AJAX请求失败：' + errorMessage);
                                            }
                                        });
                                    }
                                },
                                error: function (jqXHR, textStatus, errorMessage) {
                                    alert('AJAX请求失败：' + errorMessage);
                                }
                            });
                        }
                        else {
                            alert("请输入设计用时")
                        }
                    }
                    else {
                        alert('请选择要上传的文件！');
                    }
                }
                else {
                    alert("请先建立物料，料号")
                }

            }
            //点击打开新增供应商
            $(document).on("click", "#XINzhengWL", function () {
                Liaohao()
                $("#amt_DW").val("Pcs")
                $("#amt_WLM").removeAttr("readonly")
                $("#addwl_main").css({ "display": "block" })
            })
            $("#addwl").click(function () {
                $("#JINDN").toggle()
                $("#Yin").hide()
            })
            //新增和删除物料行
            $(function () {
                $("#xinzengWL").click(function () {
                    var $tr = $(`
                                    <tr id="WLtr">
                                        <td style="width:20px;"><input type="checkbox" class="XANZK"/></td>
                                        <td><lable id="labes">Leve0</lable></td>
                                        <td><a id="app_CkWl" href="#">物料信息</a></td>
                                        <td><input type="text"class="inwei"name="empLiao" id="empLiao" /></td>
                                        <td style="width: 200px;">
                                            <input type="text" id="empName" class="inwei" name="empName" list="seleect_codes" />
                                            <datalist id="seleect_codes" class="form-control" style="display:none"></datalist>
                                        </td>
                                        <td><input type="text"class="inwei" name="empMiao" id="empMiao" /></td>
                                        <td><input type="number"class="inwei" name="empNian" min="0" max="1000000"/></td>
                                        <td>
                                        <input type="text" id="txtxun" class="inwei" name="CL_name" list="select_codes" />
                                            <datalist id="select_codes" class="form-control" style="display:none">
                                            @foreach (var item in ViewBag.JIliang as List<Freht>)
                                            {
                                                <option value="@item.Fre_shijian">@item.Fre_beizhu</option>
                                            }
                                            </datalist>
                                        </td>
                                        <td >
                                        <input type="text" id="leibie" class="inwei" />
                                        </td>
                                        <td id="jisndd">
                                         <input type="text" id="leib_ji" class="inwei" />
                                        </td>
                                        <td><input type="number" class="inwei" name="empYong" value="1" readonly style="text-align:center;background-color:#f4eef0;"/></td>
                                        <td>
                                        <input type="text" id="txtxuns" class="inwei" name="CL_Gong" list="select_Lei" />
                                            <datalist id="select_Lei" class="form-control" style="display:none">
                                            <option>--@Resource.String63--</option>
                                            <option value="外购">@Resource.String130</option>
                                            <option value="自制">@Resource.String131</option>
                                            </datalist>
                                        </td>
                    <td style="display:none">1</td>
                    <td style="display:none"></td>
                                    </tr>
                                    `);
                    $('#WLTable').append($tr);
                    $("input,select").attr({ "autocomplete": "off" })
                })
            })
            $(document).on("click", ".quxiao", function () {
                $("#addwl_main").css({ "display": "none" })
                $("#queding").css({ "display": "block" })
                $(".amt_v").val("")
            })
            //点击切换物料一级和二级类别

            //显示ERP组织
            Zuzhi()
            function Zuzhi() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 7 },
                    success: function (path) {
                        if (path == "获取错误") {
                            alert(path)
                        } else {
                            carOPt(path)
                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            function carOPt(DL) {
                $("#SelZZ option").remove()
                $.each(DL, function (i, item) {
                    var $op = $(`<option value="${item[0]}">${item[1]}</optino>`)
                    $("#SelZZ").append($op)
                })
                $("#SelZZ").val("10.01")
            }
            //表面
            $('input[name="Biaomian"]').click(function () {
                $("#Yinchangs").toggle();
            })
            $('.quxiaoshi').click(function () {
                $("#Yinchangs").toggle();
            })

            //点击确定按钮//表面
            $(document).on("change", ".Xuanz", function () {
                $('input[name="Biaomian"]').val("")
                $("#Yinchangs").find("input[type='checkbox']").each(function () {
                    if ($(this).prop("checked")) {
                        $('input[name="Biaomian"]').val($('input[name="Biaomian"]').val() + ($('input[name="Biaomian"]').val() == "" ? "" : ",") + $(this).val())
                        $(this).prop('checked', true)
                        $(this).prop('disabled', false)
                    }
                });
            })
            //新增物料
            $(document).on("click", "#queding", function () {
                addwuliao()
            })

            //查看物料信息
            $(document).on("click", "#app_CkWl", function (e) {
                getMaterialInformation($(e.target))
            })

            //修改产品二级类别
            $(document).on("change", "#dl_wl", function (e) {
                var id = $(e.target).val()
                $.ajax({
                    url: '/Admin/Purchasing_Authority',
                    type: 'GET',
                    data: { "id": id, "state": 4 },
                    success: function (data) {
                        $("#leibei_x option").remove()
                        $.each(data, function (i, item) {
                            $("#leibei_x").append($(`<option value="${item.zl_name}">${item.zl_name}</option>`))
                        })
                    },
                    error: function () {
                        alert('Request Error');
                        Getquanx()
                    }
                })
            })
            $(document).on("change", "#leibie", function (e) {
                var id = $(e.target).val()
                $.ajax({
                    url: '/Admin/Purchasing_Authority',
                    type: 'GET',
                    data: { "id": id, "state": 4 },
                    success: function (data) {
                        $(e.target).parent().next().children().children().remove()
                        $.each(data, function (i, item) {
                            $(e.target).parent().next().children().append($(`<option value="${item.zl_name}">${item.zl_name}</option>`))
                        })
                    },
                    error: function () {
                        alert('Request Error');
                        Getquanx()
                    }
                })
            })
            function queewn() {
                var JJ = $("#LIunji").text()
                if (JJ != "") {
                    $("#div1 input,select").attr("readonly", "readonly")
                    $(".Yinchande").hide()
                    $("#divv_1").css({ "display": "block" })
                    $("#lisul").text("")
                    $("#lisul").prev().text("修改物料二级类型")
                }
            }
             function get_BOM_H() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "App_ban": $('#txtdan').val(), "state": 12 },
                    success: function (e) {
                        console.log(e)
                        queewn()
                        GF_BOM(e)
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            }
            function GF_BOM(data) {
                $('#WLTable tr').remove()
                $.each(data, function (i, item) {
                    //var KKOL = ""
                    $.ajax({
                        url: '/Admin/Purchasing_Authority',
                        type: 'GET',
                        data: { "id": item.BOM2_Sone, "state": 4 },
                        success: function (data) {
                            //KKOL = "<select id='leib_ji' class='inwei'>"
                            //$.each(data, function (i, item) {
                            //    KKOL += "<option value='" + item.zl_name + "'>" + item.zl_name + "</option>"
                            //})
                            //KKOL += "</select>"
                            var temp7 = item.BOM2_Sone;
                            var index = ""
                            index = temp7 == "1" ? "纸制品" : temp7 == "2" ? "木制品" : temp7 == "3" ? "塑料制品" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                            var $tr =$(`<tr id="WLtr">
                                       <td style="width:20px;"><input type="checkbox" class="XANZK"/></td>
                                       <td><lable id="labes">${item.BOM2_chen}</lable></td>
                                       <td><a id="app_CkWl" href="#">物料信息</a></td>
                                       <td ><input type="text" class="inwei" name="empLiao" id="empLiao" value="${item.BOM2_liao}" /></td>
                                       <td style="width: 200px;"><input type="text" class="inwei" name="empName" id="empName" value="${item.BOM2_wuLiu}" readonly/></td>
                                       <td ><input type="text" class="inwei" name="empMiao" id="empMiao" value="${item.BOM2_Guige}" /></td>
                                       <td ><input type="number" class="inwei" name="empNian" min="0" max="1000000" value="${item.BOM2_Nian}" /></td>
                                       <td>
                                           <input type="text" id="txtxun" class="inwei" name="CL_name" list="select_codes" value="${item.BOM2_fenzi}" />
                                           <datalist id="select_codes" class="form-control" style="display:none" >
                                                @foreach (var item in ViewBag.JIliang as List<Freht>)
                                                           {
                                                            <option>@item.Fre_beizhu</option>
                                                           }
                                           </datalist>
                                       </td>
                                       <td >
                                        <input type="text" class="inwei" id="leibie" value="${index}" />
                                       </td>
                                       <td id="jisndd">
                                           <input type="text" class="inwei" id="leib_ji" value="${item.BOM2_ST}" />
                                       </td>
                                       <td id="B_MS"><input type="number" class="inwei" name="empYong" value="${item.BOM2_Yong}" readonly style="text-align:center;background-color:#f4eef0;" /></td>
                                       <td>
                                           <input type="text" id="txtxuns" class="inwei" name="CL_Gong" list="select_Lei"  value="${item.BOM2_Lei}"/>
                                           <datalist id="select_Lei" class="form-control" style="display:none" >
                                               <option>--@Resource.String63--</option>
                                               <option value="外购">@Resource.String130</option>
                                               <option value="自制">@Resource.String131</option>
                                           </datalist>
                                       </td>
                                       <td style="display:none">1</td>
                                       <td style="display:none">${item.BOM2_id}</td>
                                   </tr>`
                                );
                            $('#WLTable').append($tr);
                            //$("#WLTable").children().last().children().eq(8).children().val(item.BOM2_Sone)
                            //$("#WLTable").children().last().children().eq(9).children().val(item.BOM2_ST)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                })
            }
            //提交物料的方法
            function addwuliao() {
                var temp7 = $("#dl_wl").val()
                temp7 = temp7 == "1" ? "纸质" : temp7 == "2" ? "木质" : temp7 == "3" ? "塑料" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                var GUIGE = "";
                var intkom = $(".guig").length;
                var int = 1;
                $(".guig").each(function (i, gg) {
                    if (intkom > int) {
                        GUIGE += $(gg).val() + "*"
                    } else {
                        GUIGE += $(gg).val()
                    }
                    int++;
                })
                var bm = $("#Login_bm").text()
                var d = 0;
                var JNFM = $("#LevenED").val()
                console.log(JNFM)
                var application = {
                    FM_bai: $("#amt_WLBM").val(),
                    FM_name: $("#amt_WLM").val(),
                    FM_nyl: $('#amt_NYL').val(),
                    FM_zx: $('#txtqishi').val(),
                    FM_yj: temp7,
                    FM_ej: $('#leibei_x').val(),
                    FM_bmcl: $('#amt_BMCL').val(),
                    FM_ycl: $('#amt_YCL').val(),
                    FM_ms: $('#amt_MS').val(),
                    FM_gg: GUIGE,
                    FM_ji: $("#amt_DW").val(),
                    FM_long: $("#cahns").val(),
                    FM_kuan: $("#cahns1").val(),
                    FM_gao: $("#cahns2").val(),
                    FM_Jieti: $("input[name='Biaomian']").val(),
                    FM_Zhuang: $("#shuxinss").val(),
                    FM_price: d
                };
                console.log(application)

                //bom heding
                if (application.FM_name != "" && application.FM_ej != "" && application.FM_ej != "" && application.FM_gg != "") {
                    if (application.FM_long == "" && application.FM_kuan == "" && application.FM_gao == "") {
                        alert("规格数据不符合要求")
                        return
                    }
                    if (application.FM_Jieti=="") {
                        alert("最小起订量需要选择")
                        return
                    }
                    if (application.FM_Zhuang == "") {
                        alert("物料需要选择自制或外购")
                        return
                    }
                    if (JNFM == "") {
                        alert("请选择物层级！")
                        return
                    }
                    if (temp7 == "0") {
                        alert("请选择物料一级分类！")
                        return
                    }

                    $.ajax({
                        url: "/Application/Addfor",
                        type: "POST",
                        data: { "applications": application, "names": $("#txtdan").val()} ,
                        success: function (data) {
                            if (data == "修改成功") {
                                //location.reload(true)
                                get_BOM_H()
                            } else if (data == "修改失败") {
                                alert(data)
                            } else {
                                AppendBOMLine()
                            }
                            $("#addwl_main").css({ "display": "none" })
                            $(".amt_v").val("")
                        },
                        error: function () {
                            alert("erroer");
                        },
                    })
                } else {
                    alert("请输入必须字段")
                }
            }
            //增加BOM行
            function AppendBOMLine() {
                var GUIGE = "";
                var intkom = $(".guig").length;
                var int = 1;
                $(".guig").each(function (i, gg) {
                    if (intkom > int) {
                        GUIGE += $(gg).val() + "*"
                    } else {
                        GUIGE += $(gg).val()
                    }
                    int++;
                })
                var temp = $("#amt_WLBM").val()
                var temp1 = $("#amt_WLM").val()
                var temp2 = $("#amt_NYL").val()
                var temp3 = $("#amt_BMCL").val()
                var temp4 = $("#amt_YCL").val()
                var temp5 = $("#amt_GG").val()
                var temp6 = $("#amt_MS").val()
                var temp7 = $("#dl_wl").val()
                var temp8 = $("#leibei_x").val()
                var temp9 = $("#amt_DW").val()
                var temp10 = $("#shuxinss").val()
                var temp11 = $("#LevenED").val()
                temp7 = temp7 == "1" ? "纸制品" : temp7 == "2" ? "木制品" : temp7 == "3" ? "塑料制品" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                var $tr = $(` <tr id="WLtr">
                                <td style="width:20px;"><input type="checkbox" class="XANZK"/></td>
                                <td><lable id="labes">${temp11}</lable></td>
                                <td><a id="app_CkWl" href="#">物料信息</a></td>
                                <td ><input type="text" class="inwei" name="empLiao" id="empLiao" value="${temp}" /></td>
                                <td style="width: 200px;"><input type="text" class="inwei" name="empName" id="empName" value="${temp1}" readonly/></td>
                                <td ><input type="text" class="inwei" name="empMiao" id="empMiao" value="${GUIGE}" /></td>
                                <td ><input type="number" class="inwei" name="empNian" min="0" max="1000000" value="${temp2}" /></td>
                                <td>
                                    <input type="text" id="txtxun" class="inwei" name="CL_name" list="select_codes" value="${temp9}"/>
                                    <datalist id="select_codes" class="form-control" style="display:none">
                                        @foreach (var item in ViewBag.JIliang as List<Freht>)
                                            {
  <option>@item.Fre_beizhu</option>
                                            }
                                    </datalist>
                                </td>
                                <td id="B_BMCL"><input type="text" class="inwei" id="leibie" value="${temp7}" /></td>
                                <td id="B_YCL"><input type="text" class="inwei" id="leib_ji" value="${temp8}" /></td>
                                <td id="B_MS"><input type="number" class="inwei" name="empYong" value="1" readonly style="text-align:center;background-color:#f4eef0;" /></td>
                                <td>
                                    <input type="text" id="txtxuns" class="inwei" name="CL_Gong" list="select_Lei" value="${temp10}"/>
                                    <datalist id="select_Lei" class="form-control" style="display:none">
                                        <option>--@Resource.String63--</option>
                                        <option value="外购">@Resource.String130</option>
                                        <option value="自制">@Resource.String131</option>
                                    </datalist>
                                </td>
                                <td style="display:none">1</td>
                                <td style="display:none"></td>
                            </tr>`);
                $('#WLTable').append($tr);
            }

            //获取物料信息
            function getMaterialInformation(e) {
                var temp = e.parent().parent().children()
                var temp2 = temp.eq(3).children().val()//料号
                if (temp2 == null || temp2 == "") {
                    alert("无物料！")
                } else {
                    $.ajax({
                        url: "/Application/Application",
                        type: "POST",
                        data: { "Name": temp2, "state": 16 },
                        success: function (sjik) {
                            console.log(sjik)
                            $.each(sjik, function (i, item) {
                                $("#amt_WLM").val(item.FM_name)
                                $("#amt_WLBM").val(item.FM_bai)
                                $("#cahns").val(item.FM_long)
                                $("#cahns1").val(item.FM_kuan)
                                $("#cahns2").val(item.FM_gao)
                                $("#amt_BMCL").val(item.FM_bmcl)
                                $("#amt_YCL").val(item.FM_ycl)
                                $("#amt_MS").val(item.FM_ms)
                                $("#Biaomian").val(item.FM_zx)
                                $("#amt_NYL").val(item.FM_nyl)
                                $("#amt_DW").val(item.FM_ji)
                                $("#shuxinss").val(item.FM_Zhuang)
                                $("input[name='Biaomian']").val(item.FM_Jieti)
                                var Sone = item.FM_yj;
                                Sone = Sone == "纸质" || Sone == "纸制品" ? "1" : Sone == "木质" || Sone == "木制品" ? "2" : Sone == "塑料" || Sone == "塑料制品" ? "3" : Sone == "金属制品" ? "4" : Sone == "布" ? "5" : Sone == "胶粘制品" ? "6" : Sone == "其他" ? "7" : Sone == "套件" ? "8" : Sone;
                                $("#dl_wl").val(Sone)

                                $.ajax({
                                    url: '/Admin/Purchasing_Authority',
                                    type: 'GET',
                                    data: { "id": Sone, "state": 4 },
                                    success: function (data) {
                                        console.log(data)
                                        $("#leibei_x option").remove()
                                        $.each(data, function (i, item) {
                                            $("#leibei_x").append($(`<option value="${item.zl_name}">${item.zl_name}</option>`))
                                        })
                                    },
                                    error: function () {
                                        alert('Request Error2');
                                        Getquanx()
                                    }
                                })
                                $("#leibei_x").val(item.FM_ej)
                            })
                        },
                        error: function () {
                            alert("erroer");
                        },
                    })
                    $("#addwl_main").css({ "display": "block" })
                }
            }
            $("#Quxiao").click(function () {
                $(".YCFile").hide()
            })
            $("#Tiao").click(function () {
                $("#JINDN").hide()
                $("#Yin").toggle()
            })
            $(document).on("change", "#SJ_HANG1", function () {
                changehangye2()
            })

            function changehangye2() {
                var id = $("#SJ_HANG1").val()
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "CL_ID": id, "state": 10 },
                    success: function (sjik) {
                        $("#SJ_HANG2 option").remove();
                        $("#SJ_HANG2").append($(`<option value="0" >--@Resource.String63--</option>`));
                        $.each(sjik, function (i, item) {
                            var $tr = $(`<option value="${item.isu_id}" >${item.isu_name}</option>`);
                            $("#SJ_HANG2").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }

            $(document).on("change", "#hangye1", function () {
                changehangye()
            })

            function changehangye() {
                var id = $("#hangye1").val()
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "CL_ID": id, "state": 10 },
                    success: function (sjik) {
                        $("#hangye2 option").remove();
                        $("#hangye2").append($(`<option value="0" >--@Resource.String63--</option>`));
                        $.each(sjik, function (i, item) {
                            var $tr = $(`<option value="${item.isu_id}" >${item.isu_name}</option>`);
                            $("#hangye2").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }


            function Liaohao() {
                $.ajax({
                    url: '/Formations/FomShu',
                    type: 'POST',
                    data: { "steate": 1 },
                    success: function (e) {
                        var shu = Number(e) + 1;
                        var afi = "WL" + "000" + shu;
                        if (shu => 10) {
                            afi = "WL" + "00" + shu
                        }
                        if (shu => 100) {
                            afi = "WL" + "0" + shu
                        }
                        if (shu > 1000) {
                            afi = "WL" + shu
                        }
                        //写入随机申请单号
                        $("#amt_WLBM").val(afi)
                    },
                    error: function () {
                        alert("错误")
                    }
                })
            }
        })
        //获取备注信息
        function gettbz() {
            var kan = $("#txtdan").val();
            $.ajax({
                url: "/Application/Application",
                type: "POST",
                data: { "App_ban": kan, "state": 4 },
                success: function (sjik) {
                    $("#RZ_gwzr div").remove();
                    $.each(sjik, function (i, item) {
                        var $tr = $(`
                                     <div>
                                         <div>
                                             <span>${item.B_BR}</span><span>${item.B_Date}</span>
                                         </div>
                                         <div>
                                             ${item.B_bei}
                                         </div>
                                     </div>`);
                        $("#RZ_gwzr").append($tr);
                    })
                },
                error: function () {
                    alert("erroer");
                },
            })
        }
        //获取图纸信息
        Load_design_table()
        //获取图纸信息
        function Load_design_table() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 3, "App_ban": $('#txtdan').val() },
                    success: function (path) {
                        createFJ(path)
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
        function createFJ(fgggh) {
                $("#logfuj tr").remove();
                $("#div3__tb tr").remove();
                $("#div5_tb tr").remove();
                var ind1 = 1
                var ind2 = 1
                var temp=0
                $.each(fgggh, function (i, item) {
                    var x = item.De_dizhi
                    if (item.DE_lei == "图纸") {
                        if (item.DE_tuiLei == "驳回") {
                            var DE_tuiLeiDE="设计主管驳回"
                            var $tr = (`
                                <tr class="log_tr">
                                    <td style="display:none">${item.DE_id}</td>
                                    <td>${ind1}</td>
                                    <td><input type="text" value="${item.De_dizhi}" readonly/></td>
                                    <td>${item.bom_id}</td>
                                    <td>${item.De_shijian}</td>
                                    <td>${item.De_ren}</td>
                                    <td>
                                        <input type="number" readonly="readonly" value="${item.DE_Slong}" style="width:60px;height:30px"/>
                                    </td>
                                    <td class="sjtzt"><a id="ckbhly_tz" href="#" >${DE_tuiLeiDE}</a></td>
                                    <td><a href="#" id="log_SC">删除</a>/<a href="#" id="log_SXSC">重新上传</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                </tr>`);
                            $("#div3__tb").append($tr);
                        }
                        else if (item.DE_tuiLei == "待审核") {
                            var DE_tuiLeiDE = "待设计主管审核"
                            var $tr = (`
                                <tr class="log_tr">
                                    <td style="display:none">${item.DE_id}</td>
                                    <td>${ind1}</td>
                                    <td><input type="text" value="${item.De_dizhi}" readonly/></td>
                                    <td>${item.bom_id}</td>
                                    <td>${item.De_shijian}</td>
                                    <td>${item.De_ren}</td>
                                    <td>
                                        <input type="number" readonly="readonly" value="${item.DE_Slong}" style="width:60px;height:30px"/>
                                    </td>
                                    <td class="sjtzt">${DE_tuiLeiDE}</td>
                                    <td><a href="#" id="log_SC" class="bianjiann">删除</a>/<a href="#" id="log_SXSC" class="bianjiann">重新上传</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                </tr>`);
                            $("#div3__tb").append($tr);
                        }
                        else {
                            var DE_tuiLeiDE = "设计主管通过"
                            var $tr = (`
                                <tr class="log_tr">
                                    <td style="display:none">${item.DE_id}</td>
                                    <td>${ind1}</td>
                                    <td><input type="text" value="${item.De_dizhi}" readonly/></td>
                                    <td>${item.bom_id}</td>
                                    <td>${item.De_shijian}</td>
                                    <td>${item.De_ren}</td>
                                    <td>
                                        <input type="number" readonly="readonly" value="${item.DE_Slong}" style="width:60px;height:30px"/>
                                    </td>
                                    <td class="sjtzt">${DE_tuiLeiDE}</td>
                                    <td><a href="#" id="log_SC">删除</a>/<a href="#" id="log_SXSC">重新上传</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                </tr>`);
                            $("#div3__tb").append($tr);
                        }
                        ind1++
                        temp += item.DE_Slong * 1
                    }
                    else {
                        var shundjian = ""
                        if ($("#Login_sf").text() == "销售助理" | $("#Login_sf").text() == "业务主管" | $("#Login_sf").text() == "业务发展部经理" | $("#Login_sf").text() == "客户经理" | $("#Login_N").text() == item.De_ren) {
                            shundjian = " | <span id='SferJ'>删除</span>"
                        }
                        var $tr = (`
                        <tr class="log_tr">
                            <td style="display:none">${item.DE_id}</td>
                            <td>${ind2}</td>
                            <td><input type="text" value="${item.De_dizhi}"/></td>
                            <td>${item.De_shijian}</td>
                            <td>${item.De_ren}</td>
                            <td><a href="/Contracts/Download_file?path=${x}" id="log_SZ">@Resource.String582</a>${shundjian}</td>
                        </tr>`);
                        $("#logfuj").append($tr);
                        ind2++
                    }
                    if ($("#Login_zj").text() == "2" && item.DE_tuiLei=="待审核") {
                    var $tr =
                        (`
                            <tr class="log_tr">
                                <td style="display:none">${item.DE_id}</td>
                                <td>${i + 1}</td>
                                <td><input type="text" value="${item.De_dizhi}"/></td>
                                <td>${item.bom_id}</td>
                                <td>${item.De_shijian}</td>
                                <td>${item.De_ren}</td>
                                <td>
                                    <input type="number"  value="${item.DE_Slong}" style="width:60px;height:30px"/>
                                </td>
                                <td class="WT_SHZT">${item.DE_tuiLei}</td>
                                <td><a href="#" class="Log_sh" id="change_time">@Resource.String575</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">@Resource.String582</a></td>
                                <td><a href="#" id="WT_pass">@Resource.String584</a>/<a href="#" id="log_back">@Resource.String583</a></td>
                            </tr>
                        `);
                        $("#div5_tb").append($tr);
                    }
                })
                $("#SJ_ZYS").text(temp)
            }
        function FUzher(a) {
            $.ajax({
                url: '/Application/Application',
                type: 'POST',
                data: { "state": 30 },
                success: function (path) {
                    if (path == "获取错误") {
                        alert(path)
                    } else {
                        $("#XMfzr option").remove()
                        $.each(path, function (i, item) {
                            var $op = $(`<option value="${item[0]}">${item[0]}</optino>`)
                            $("#XMfzr").append($op)
                        })
                    }
                    $("#XMfzr").val(a)
                },
                error: function () {
                    alert("系统错误!");
                }
            })
        }
        $(document).on("click", "#SferJ", function () {
            var id = $(this).parent().parent().children().eq(0).text()
            if (confirm("是否删除这条附件！！！！！")) {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 31, "DE_id": id },
                    success: function (path) {
                        if (path == "0") {
                            alert("删除失败")
                        } else {
                            alert("删除成功")
                            Load_design_table()
                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
        })
        //新增和删除物料行
        $(function () {
            //删除物料行
            $("#DELcheck").click(function () {
                if (!confirm('确定要删除这些物料吗?')) {
                    return;
                } else {
                    RemoverTR()
                }
            })
            //点击修改时间
            $(document).on("click", "#change_time", function (e) {
                change_time($(e.target))
            })
            function change_time(e) {
                DE_id = e.parent().parent().children().first().text()//设计图id
                DE_Slong = e.parent().parent().children().eq(5).children().val()
                var BZJG = [];
                BZJG.push({
                    DE_id: DE_id,
                    DE_Slong: DE_Slong

                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Contracts/Modify_des_Slong",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        alert(text)
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }
            function RemoverTR() {
                var formation = [];
                $("input[class='XANZK']:checked").each(function (index, obj) {
                    console.log($(obj).parent().parent().children().eq(13).text())
                    var shunnn = $(obj).parent().parent().children().eq(13).text()
                    if (shunnn !="") {
                        formation.push({
                            FM_bai: shunnn,
                            FM_name: $("#txtdan").val(),
                        })
                    } else {
                        $(obj).parent().parent().remove()
                    }
                })
                console.log("共" + formation.length + "数据");
                console.log(formation);
                if (formation.length>0) {
                    $.ajax({
                        url: "/Application/RemoveMaterial",
                        type: "POST",
                        data: JSON.stringify(formation),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            alert(text)
                            var check = $("input[class='XANZK']:checked").parent().parent().get()
                            $(check).remove();
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })
                }
            }
        })
        $(document).on("click", "#btnWCXM", function (e) {
            efj($(e.target).text())
        })
        $(document).on("click", "#btnJSXM", function (e) {
            efj($(e.target).text())
        })
        function efj(e) {
            var id = $("#txtdan").val();
            var index = e
            var zhuang = ""
            var now = new Date($.now());
            var year = (now.getFullYear()).toString();
            var month = (now.getMonth() + 1).toString();
            var date = (now.getDate()).toString();
            var time = year + "/" + month + "/" + date
            var num = $("#Login_N").text()
            if (index == "完成" || index=="通过") {
                zhuang = "5"
            }
            else if (index=="结束") {
                zhuang="-99"
            }
            console.log(zhuang)
            var BZJG = [];
            BZJG.push({
                D_Ton: id,
                D_zhuang: zhuang,
                D_CD: time,
                D_TCA: num
            })
            console.log("共" + BZJG.length + "数据");
            console.log(BZJG);
            $.ajax({
                url: "/Contracts/Modify_des_zhuang2",
                type: 'POST',
                data: JSON.stringify(BZJG),
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (text) {
                    if (text == "项目继续") {
                        window.location.href = "/Detailed/Boms?names=" + id;
                    }
                    else if (text == "项目结束") {
                        alert(text)
                        window.location.href = "/Contracts/Inspect_Contracts";
                    }
                    else if (text == "项目完成") {
                        alert(text)
                        window.location.href = "/Contracts/Inspect_Contracts";
                    }
                },
                error: function (text) {
                    alert("系统错误" + text);
                }
            })
        }


        function BOMINsjj() {
            var kan = $("#txtdan").val();
            $.ajax({
                url: "/Application/Application",
                type: "POST",
                data: { "App_ban": kan, "state": 9 },
                success: function (sjik) {
                    createBom(sjik);
                },
                error: function () {
                    alert("erroer");
                },
            })
        }
        function createBom(sjik) {
            $("#WLTable tr").remove();
            $.each(sjik, function (i, item) {
                var $tr = $(`<tr>
                                <td><input type="checkbox"class="XANZK"/></td>
                                <td><input type="text" class="inwei" value="${item.BOM2_chen}" readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_liao}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_wuLiu}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_Guige}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_Nian}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_fenzi}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_Sone}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_ST}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_Yong}"readonly></td>
                                <td><input type="text" class="inwei"value="${item.BOM2_Lei}"readonly></td>
                                <td style="display:none">0</td>
                                <td style="display:none">${item.BOM2_id}</td>
                            </tr>`);
                $("#WLTable").append($tr);
            })
        }
        //生成单号和发起时间
        $(function () {
            randomGeneration()
            function randomGeneration() {
                var id = $("#appp_id").text()
                var JJ = $("#LIunji").text()
                var x = 1000000
                var y = 9999999
                var num = parseInt(Math.random() * (x - y + 1) + y)
                if (id == 0) {
                    $.ajax({
                        url: '/Cuobaojia/Application',
                        type: 'POST',
                        data: {"state": 10 },
                        success: function (e) {
                            $("#txtdan").val(e)
                            $("#CJR").val($("#Login_N").text())
                        },
                        error: function () {
                            alert("系统错误！");
                        }
                    })
                }
                else {
                    $.ajax({
                        url: '/Application/Application',
                        type: 'POST',
                        data: { "id": id, "state": 11 },
                        success: function (e) {
                            var BUZHO=""
                            $.each(e, function (i, item) {
                                $('#txtdan').val(item.AP_bian)
                                $("#CJR").text(item.AP_ren)
                            })
                            //getContracts()
                            get_BOM_H()
                            //BOMINsjj()
                            Load_design_table()
                            gettbz()
                            shinfdko()
                        },
                        error: function () {
                            alert("系统错误！");
                        }
                    })
                }
                queewn()
                if ($("#Login_bm").text() == "业务" || $("#Login_bm").text() == "设计") {
                    $("#divSP_FP").css({ "display": "none" })
                    $("#divv_4").css({ "display": "none" })
                    $("#divv_5").css({ "display": "none" })
                    $("#divv_1").css({ "display": "block" })
                    $("#divv_2").css({ "display": "block" })
                    //if ($("#Login_sf").text() == "客户经理" || $("#Login_sf").text() == "销售助理") {
                    //    if ($("#appp_Sjzt").text() == "设计委托") {
                    //        $("#divv_7").css({ "display": "block" })
                    //        $("#divv_8").css({ "display": "block" })
                    //    }
                    //}
                    //else {
                    //    $.ajax({
                    //        url: "/Application/Application",
                    //        type: "POST",
                    //        data: { "id": id, "state": 18 },
                    //        success: function (sjik) {
                    //            if ($("#appp_Sjzt").text() == "设计委托" && sjik == "显示") {
                    //                //$("#divv_7").css({ "display": "block" })
                    //                $("#divv_8").css({ "display": "block" })
                    //            }
                    //        },
                    //        error: function () {
                    //            alert("erroer");
                    //        },
                    //    })
                    //}
                }
                if (JJ != "") {
                    $("#div1 input,select").attr("readonly", "readonly")
                    $(".Yinchande").hide()
                    $("#divv_1").css({ "display": "block" })
                    $("#lisul").text("")
                    $("#lisul").prev().text("修改物料二级类型")
                }
            }

            function queewn() {
                var JJ = $("#LIunji").text()
                if (JJ != "") {
                    $("#div1 input,select").attr("readonly", "readonly")
                    $(".Yinchande").hide()
                    $("#divv_1").css({ "display": "block"})
                    $("#lisul").text("")
                    $("#lisul").prev().text("修改物料二级类型")
                }
            }
            function hangye20(ws) {
                var id = $("#hangye1").val()
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "CL_ID": id, "state": 10 },
                    success: function (sjik) {
                        $("#hangye2 option").remove();
                        $("#hangye2").append($(`<option value="0" >--@Resource.String63--</option>`));
                        $.each(sjik, function (i, item) {
                            var $tr = $(`<option value="${item.isu_id}" >${item.isu_name}</option>`);
                            $("#hangye2").append($tr);
                        })
                        $("#hangye2").val(ws);
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
            function shinfdko() {
                var DTon = $('#txtdan').val()
                $.ajax({
                    url: "/Application/Application",
                    type: 'GET',
                    data: { "state": 14, "App_ban": DTon },
                    success: function (data) {
                        $.each(data, function (i, item) {
                            var $tr=$(` <tr style="background-color:white;text-align:center">
                        <td>
                           ${item.DE_nae}
                        </td>
                        <td>${item.DE_bumeng}</td>
                        <td>${item.DE_phone}</td>
                        <td><input  type="text" value="${item.SJ_BZ}" readonly/></td>
                        <td></td>
                    </tr>`)
                            $("#WT_JDR_Tb").append($tr)
                        })
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            $("#btnreste").click(function () {
                window.location.href = "/Home/GYBOM"
            })
            function getContracts() {
                var DTon = $('#txtdan').val()
                $.ajax({
                    url: "/Contracts/Design_order",
                    type: 'GET',
                    data: { "state": 1, "DTon": DTon },
                    success: function (data) {
                        Show_old_data(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }

            //写入旧数据的方法
            function Show_old_data(data) {
                $.each(data, function (i, item) {
                    $("#WT_sqrq").text(item.D_Applic)
                    $("#WT_yqrq").val(item.D_reDate)
                    $("#WT_rwdh").text(item.D_Ton)
                    $("#WT_sqr").val(item.D_App)
                    $("#WT_sqshr").val(item.D_AppRevi)
                    $("#WT_khmc").val(item.D_CN)
                    $("#WT_cpmc").val(item.D_PN)
                    $("#WT_dj").val(item.D_LV)
                    $("#WT_sjhs").val(item.D_DT)
                    $('#WT_cpzl').val(item.D_PW)
                    $('#WT_ddsm').val(item.D_SI)
                    $('#WT_qtxx').val(item.D_OI)
                    $('#WT_qtyq').val(item.D_OR)
                    $('#WT_csyq').val(item.D_SR)
                    $('#WT_jdr').val(item.D_REC)
                    $('#WT_jdshy').val(item.D_AR)
                    $('#WT_wcrq').text(item.D_CD)
                    $('#WT_wcshy').val(item.D_TCA)
                    $('#WT_xmjz').val(item.D_price)
                    $("#WT_bz").text(item.D_zhuang)
                    $('#WT_rwdlx').val(item.D_take)
                    $('#Derowid').text(item.D_id)
                    $('#ZhuathhskM').text(item.D_zhuang)
                    console.log($("WT_bz").text())
                    //设计类别
                    if (item.D_DE != null) {
                        var D_DE = item.D_DE.split(" ")
                        D_DE.pop()
                        console.log(D_DE)
                        $("input[name='WT_sjlb']").each(function (i, a) {
                            if (D_DE.includes(a.value) == true) {
                                a.checked = true
                            }
                        })
                    }
                    //任务单类型
                    if (item.D_take != null) {
                        var D_DE = item.D_take.split(" ")
                        D_DE.pop()
                        console.log(D_DE)
                        $("input[name='WT_sjlb']").each(function (i, a) {
                            if (D_DE.includes(a.value) == true) {
                                a.checked = true
                            }
                        })
                    }
                    if (item.D_MOF != null) {
                        //运输方式
                        var D_MOF = item.D_MOF.split(" ")
                        D_MOF.pop()
                        console.log(D_MOF)
                        $("input[name='WT_ysfs']").each(function (i, b) {
                            if (D_MOF.includes(b.value) == true) {
                                b.checked = true
                            }
                        })
                    }
                    if (item.D_PT != null) {
                        //包装方式
                        var D_PT = item.D_PT.split(" ")
                        D_PT.pop()
                        console.log(D_PT)
                        $("input[name='WT_bzlx']").each(function (i, c) {
                            if (D_PT.includes(c.value) == true) {
                                c.checked = true
                            }
                        })
                    }
                    if (item.D_PR != null) {
                        //防护要求
                        var D_PR = item.D_PR.split(" ")
                        D_PR.pop()
                        console.log(D_PR)
                        $("input[name='WT_fhyq']").each(function (i, d) {
                            if (D_PR.includes(d.value) == true) {
                                d.checked = true
                            }
                        })
                    }
                    if (item.D_PA != null) {
                        //项目附件
                        var D_PA = item.D_PA.split(" ")
                        D_PA.pop()
                        console.log(D_PA)
                        $("input[name='WT_xmbzfjxx']").each(function (i, e) {
                            if (D_PA.includes(e.value) == true) {
                                e.checked = true
                            }
                        })
                    }
                    console.log(item.D_zhuang)
                    if (item.D_zhuang == "3") {
                        //,#divv_4
                        $("#WT_JDR_TJ,#TJIAO_JDRF").css({"display":"none"})
                    }
                    var jsi = $("#JNDKO").text()
                    if (jsi == "未确认") {
                        $("#divv_2").css({ "display": "block" })
                    }
                    if (item.D_zhuang > 3 && $("#Login_bm").text() == "业务") {
                        $("#divv_1,#divv_2").css({ "display": "none" })
                    }
                    if (item.D_zhuang == 4 && $("#Login_bm").text() == "业务") {
                        $("#divv_4").css({ "display": "block" })
                    }
                    if (item.D_zhuang == 5 && $("#Login_bm").text() == "业务" && $("#Selse").val() == "S") {
                        $("#divv_4").css({ "display": "block" })
                    } else if (item.D_zhuang == 5 && $("#Login_bm").text() == "业务"){
                        $("#divv_4").css({ "display": "none" })
                    }
                })
            }


            function get_BOM_H() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "App_ban": $('#txtdan').val(), "state": 12 },
                    success: function (e) {
                        console.log(e)
                        queewn()
                        GF_BOM(e)
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            }
            function GF_BOM(data) {
                $('#WLTable tr').remove()
                $.each(data, function (i, item) {
                    //var KKOL = ""
                    $.ajax({
                        url: '/Admin/Purchasing_Authority',
                        type: 'GET',
                        data: { "id": item.BOM2_Sone, "state": 4 },
                        success: function (data) {
                            //KKOL = "<select id='leib_ji' class='inwei'>"
                            //$.each(data, function (i, item) {
                            //    KKOL += "<option value='" + item.zl_name + "'>" + item.zl_name + "</option>"
                            //})
                            //KKOL += "</select>"
                            var temp7 = item.BOM2_Sone;
                            var index = ""
                            index = temp7 == "1" ? "纸制品" : temp7 == "2" ? "木制品" : temp7 == "3" ? "塑料制品" : temp7 == "4" ? "金属制品" : temp7 == "5" ? "布" : temp7 == "6" ? "胶粘制品" : temp7 == "7" ? "其他" : temp7 == "8" ? "套件" : temp7;
                            var $tr =$(`<tr id="WLtr">
                                       <td style="width:20px;"><input type="checkbox" class="XANZK"/></td>
                                       <td><lable id="labes">${item.BOM2_chen}</lable></td>
                                       <td><a id="app_CkWl" href="#">物料信息</a></td>
                                       <td ><input type="text" class="inwei" name="empLiao" id="empLiao" value="${item.BOM2_liao}" /></td>
                                       <td style="width: 200px;"><input type="text" class="inwei" name="empName" id="empName" value="${item.BOM2_wuLiu}" readonly/></td>
                                       <td ><input type="text" class="inwei" name="empMiao" id="empMiao" value="${item.BOM2_Guige}" /></td>
                                       <td ><input type="number" class="inwei" name="empNian" min="0" max="1000000" value="${item.BOM2_Nian}" /></td>
                                       <td>
                                           <input type="text" id="txtxun" class="inwei" name="CL_name" list="select_codes" value="${item.BOM2_fenzi}" />
                                           <datalist id="select_codes" class="form-control" style="display:none" >
                                                @foreach (var item in ViewBag.JIliang as List<Freht>)
                                                           {
                                                            <option>@item.Fre_beizhu</option>
                                                           }
                                           </datalist>
                                       </td>
                                       <td >
                                        <input type="text" class="inwei" id="leibie" value="${index}" />
                                       </td>
                                       <td id="jisndd">
                                           <input type="text" class="inwei" id="leib_ji" value="${item.BOM2_ST}" />
                                       </td>
                                       <td id="B_MS"><input type="number" class="inwei" name="empYong" value="${item.BOM2_Yong}" readonly style="text-align:center;background-color:#f4eef0;" /></td>
                                       <td>
                                           <input type="text" id="txtxuns" class="inwei" name="CL_Gong" list="select_Lei"  value="${item.BOM2_Lei}"/>
                                           <datalist id="select_Lei" class="form-control" style="display:none" >
                                               <option>--@Resource.String63--</option>
                                               <option value="外购">@Resource.String130</option>
                                               <option value="自制">@Resource.String131</option>
                                           </datalist>
                                       </td>
                                       <td style="display:none">1</td>
                                       <td style="display:none">${item.BOM2_id}</td>
                                   </tr>`
                                );
                            $('#WLTable').append($tr);
                            //$("#WLTable").children().last().children().eq(8).children().val(item.BOM2_Sone)
                            //$("#WLTable").children().last().children().eq(9).children().val(item.BOM2_ST)
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })

                })
            }
        })

        //点击按钮把申请单信息写入数据库
        $(function () {
            $(document).on("click", ".btn_app_tj", function (e) {
                var JJ = $("#LIunji").text()
                if ($("#LIunji").text() == "") {
                    if ($(e.target).val() == "提交") {
                        if (confirm("是否提交")) {
                            var index = ""
                            $("#WLTable tr").each(function (i, temp) {
                                if ($("input[name='CL_Gong']", temp).val() =="") {
                                    index += $("input[name='empName'] ", temp).val() + " "
                                }
                            })
                            if (index == "") {
                                addAPPlication($(e.target).val())
                            }
                            else {
                                alert("以下物料:" + index + "请选择自制或外购")
                            }
                        }
                    }
                    else if ($(e.target).val() == "保存") {
                        addAPPlication($(e.target).val())
                    }
                } else {
                    if (confirm("请确定单据信息是否正确，是否存在未维护信息")) {
                        var index = ""
                        $("#WLTable tr").each(function (i, temp) {
                            if ($("input[name='CL_Gong']", temp).val() != "自制" && $("input[name='CL_Gong']", temp).val() != "外购") {
                                index += $("input[name='empName'] ", temp).val() + " "
                            }
                        })
                        if (index == "") {
                            var sjin = $("#txtdan").val()
                            window.location.href = JJ + "?names=" + sjin;
                        }
                        else {
                            alert("以下物料:" + index+"请选择自制或外购")
                        }

                    }
                }
            })
            function addAPPlication(e) {
                var hang = $("#WLTable tr").length;
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var sqrq = year + "-" + month + "-" + date
                var Buzdy = e =="提交"?"2":"1"
                var application = {
                    AP_ren: $("#Login_N").text(),
                    Ap_bian: $('#txtdan').val(),
                    App_qishi: sqrq,
                    App_bu: Buzdy,
                    App_BanB: 1,
                    App_bei: e,
                };
                if (e == "提交") {
                    if (hang < 1) {
                        alert("单据物料未添加，请先添加物料在进行提交！！！")
                    }
                    else {
                        $.ajax({
                            url: "/Cuobaojia/AddApplication",
                            type: "POST",
                            data: application,
                            success: function (data) {
                                if (data != "添加失败") {
                                    var shun = data.split('+')
                                    var SD = shun[0];
                                    var SD1 = shun[1];
                                    $("#txtdan").val(SD)
                                    $("#appp_id").text(SD1)
                                    Tboms(SD);
                                    window.location.href = "/Cuobaojia/Boms?names=" + $('#txtdan').val();
                                } else {
                                    alert(data)
                                }
                            },
                            error: function () {
                                alert("erroer");
                            },
                        })
                    }

                }
                else {
                    if (hang < 1) {
                        alert("单据物料未添加，请先添加物料在进行提交！！！")
                    } else {
                        $.ajax({
                            url: "/Cuobaojia/AddApplication",
                            type: "POST",
                            data: application,
                            success: function (data) {
                                if (data != "添加失败") {
                                    var shun = data.split('+')
                                    var SD = shun[0];
                                    var SD1 = shun[1];
                                    $("#txtdan").val(SD)
                                    $("#appp_id").text(SD1)
                                    Tboms(SD);
                                } else {
                                    alert(data)
                                }
                            },
                            error: function () {
                                alert("erroer");
                            },
                        })
                    }
                }
            }
            function Tboms(KI) {
                var BOMinise = [];
                var shen = KI;
                var hu = 0;
                $("#WLTable tr").each(function (index, obj) {
                    if ($("#labes", obj).html() == "Leve0") {
                        hu = hu + 1 * 1000;
                    }
                    if ($("#labes", obj).html() == "leve1") {
                        hu = hu +"-A";
                    }
                    var Sone = $("#leibie", obj).val() == null ? $("#leibie", obj).val() : $("#leibie", obj).val();
                    console.log(Sone)
                    var Sted = $("#leib_ji", obj).val() == null ? $("#leib_ji", obj).val() : $("#leib_ji", obj).val();
                    Sone = Sone == "纸质" || Sone == "纸制品" ? "1" : Sone == "木质" || Sone == "木制品" ? "2" : Sone == "塑料制品" || Sone == "塑料" ? "3" : Sone == "金属制品" ? "4" : Sone == "布" ? "5" : Sone == "胶粘制品" ? "6" : Sone == "其他" ? "7" : Sone == "套件"?"8": Sone;
                    BOMinise.push({
                        BOM2_chen: $("#labes", obj).html(),//层级
                        BOM2_wuLiu: $("input[name='empName'] ", obj).val(),//物料信息
                        BOM2_liao: $("input[name='empLiao'] ", obj).val(),//料号
                        BOM2_Guige: $("input[name='empMiao'] ", obj).val(),//产品规格
                        BOM2_Nian: $("input[name='empNian'] ", obj).val(),//年用量
                        BOM2_fenzi: $("input[name='CL_name']", obj).val(), //计量单位
                        BOM2_Yong: $("input[name='empYong'] ", obj).val(),//Bom 用量
                        BOM2_Lei: $("input[name='CL_Gong']", obj).val(),/*自制或采购*/
                        BOM2_bian: shen,
                        BOM2_Ctime: $("#txtqishi").val(),
                        BOM2_BQing: hu,
                        BOM2_Zhuang: 1,
                        BOM2_Sone: Sone,
                        BOM2_ST: Sted
                        //预留添加标识
                    })
                    console.log("共" + BOMinise.length + "数据");
                    console.log(BOMinise);
                })

                //发出请求
                $.ajax({
                    url: "/Cuobaojia/AddAppli",
                    type: "POST",
                    data: JSON.stringify(BOMinise),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        if (text >0) {
                            alert("添加成功")
                        } else {
                            alert("添加失败" + text.msg);
                        }
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }
            $("#btnUpdate").click(function () {
                if ($("#Login_sf").text() == "设计主管") {
                    var shunf = $("#ZhuathhskM").text()
                    var sjin ="提交"
                    append_Contracts(shunf, sjin)
                }
            })

            function append_Contracts(zhuang,Tishi) {
                var jdr = ""
                $(".WT_JDR_a2").each(function (i, item) {
                    var index = $(item).val()
                    var temp = index.split(" ")
                    var lastElement = temp[1];
                    jdr += lastElement + " "
                })
                var box1_1 = ""
                var box2_1 = ""
                var box3_1 = ""
                var box4_1 = ""
                var box5_1 = ""
                var box1 = $("#WT_sjlb input[type=checkbox]:checked").serializeArray()
                var box2 = $("input[name='WT_ysfs']:checked").serializeArray()
                var box3 = $("input[name='WT_bzlx']:checked").serializeArray()
                var box4 = $("input[name='WT_fhyq']:checked").serializeArray()
                var box5 = $("input[name='WT_xmbzfjxx']:checked").serializeArray()
                $.each(box1, function (i, item) {
                    box1_1 += item.value + " "
                })
                $.each(box2, function (i, item) {
                    box2_1 += item.value + " "
                })
                $.each(box3, function (i, item) {
                    box3_1 += item.value + " "
                })
                $.each(box4, function (i, item) {
                    box4_1 += item.value + " "
                })
                $.each(box5, function (i, item) {
                    box5_1 += item.value + " "
                })

                var bcxx = {
                    D_Applic: $('#WT_sqrq').text(),
                    D_reDate: $('#WT_yqrq').val(),
                    D_price: $('#WT_xmjz').val(),
                    D_Ton: $('#WT_rwdh').text(),
                    D_App: $('#WT_sqr').val(),
                    D_AppRevi: $('#WT_sqshr').val(),
                    D_CN: $('#WT_khmc').val(),
                    D_PN: $('#WT_cpmc').val(),
                    D_take: $('#WT_rwdlx option:selected').val(),
                    D_DE: box1_1,
                    D_LV: $('#WT_dj').val(),
                    D_DT: $('#WT_sjhs ').val(),
                    D_PW: $('#WT_cpzl').val(),
                    D_SI: $('#WT_ddsm').val(),
                    D_OI: $('#WT_qtxx').val(),
                    D_MOF: box2_1,
                    D_PT: box3_1,
                    D_PR: box4_1,
                    D_OR: $('#WT_qtyq').val(),
                    D_SR: $('#WT_csyq').val(),
                    D_PA: box5_1,
                    D_REC: jdr,
                    D_AR: $('#WT_jdshy').val(),
                    D_CD: $('#WT_wcrq').text(),
                    D_TCA: $('#WT_wcshy').val(),
                    D_zhuang: zhuang,
                    D_id: $("#Derowid").text()
                };
                console.log(bcxx)
                if (Tishi != "提交") {
                    $.ajax({
                        url: "/Contracts/Temporary_storage",
                        type: "POST",
                        data: bcxx,
                        success: function (data) {
                            console.log(data)
                        },
                        error: function (data) {
                            alert("erroer");
                        },
                    })
                } else {
                    if ($("#Login_bm").text() == "业务") {
                        if (bcxx.D_PW == "" || bcxx.D_SI == "" || bcxx.D_OI == "" || bcxx.D_MOF == "" || bcxx.D_PT == "" || bcxx.D_OR == "" || bcxx.D_SR == "") {
                            alert("红框内为必填项")
                            duandian = "1"
                        }
                        else {
                            $.ajax({
                                url: "/Contracts/Temporary_storage",
                                type: "POST",
                                data: bcxx,
                                success: function (data) {
                                    console.log(data)
                                },
                                error: function (data) {
                                    alert("erroer");
                                },
                            })
                        }
                    }
                    else {
                        if (bcxx.D_take == "" || bcxx.D_DE == "") {
                            alert("等级和类型不能为空！")
                        } else {
                            $.ajax({
                                url: "/Contracts/Temporary_storage",
                                type: "POST",
                                data: bcxx,
                                success: function (data) {
                                    alert(data)
                                },
                                error: function (data) {
                                    alert("erroer");
                                },
                            })
                        }
                    }
                }
            }

        })

        function jisndd(snMk) {
            var $lishu7 = $(`<ul id="lisul" class="row col-sm-5">
                                        <li class="lisu">1</li>&rArr;
                                        <li class="lisu"></li>&rArr;
                                        <li class="lisu"></li>&rArr;
                                        <li class="lisu"></li>&rArr;
                                        <li class="lisu"></li>&rArr;
                                        <li class="lisu"></li>&rArr;
                                        <li class="lisu"></li>
                                    </ul>`)
            var $lishu3 = $(`<ul id="lisul" class="row col-sm-5">
                                        <li class="lisu">1</li>&rArr;
                                        <li class="lisu"></li>&rArr;
                                        <li class="lisu"></li>
                                    </ul>`)
            if (snMk == "纯设计") {
                $("#lisul ").replaceWith($lishu3)
            } else {
                $("#lisul").replaceWith($lishu7)
            }
        }
        $(document).on("change", "#txtleix", function () {
            var snedMk = $(this).val()
            jisndd(snedMk)
        })
        $("#yin").css({ "display": "block" });
        $("#Bomz").addClass("disabled");
        //客户名输入事件
        $(function () {
            $("#txtname").blur(function () {
                var shun = $("#txtname").val();
                var Zhu = $("#SelZZ").val()
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "Name": shun, "Shunqi": Zhu,"state": 1 },
                    success: function (e) {
                        createSel(e);
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            })
            function createSel(e) {
                $("#seleect_codeDE option").remove();
                $.each(e, function (i, item) {
                    var $tr = (`<option value="${item.CL_name}">`);
                    var sho = item.CL_sho;
                    var juli = item.CL_ju;
                    $("#seleect_codeDE").append($tr);
                    //$("#txtsho").val(sho);
                    $("#txtjuli").val(juli);
                    $("#BIanhao").text(item.CL_bian)
                })
            }
        })
        //绑定物料库
        $(document).on("keyup", "#empLiao", function (x) {
            var shun = $(x.target).val();
            var Zhu = $("#SelZZ").val()
            var JHIK = 0;
            $(".XANZK").each(function (i, item) {
                var shunSED = $(item).parent().parent().children().eq(3).children().val()//物料编码
                if (shun == shunSED) {
                    JHIK++;
                }
            })
            if (JHIK > 1) {
                $(x.target).css({ "background": "red" })
                console.log(JHIK)
            } else {
                $.ajax({
                    url: '/Cuobaojia/Application',
                    type: 'POST',
                    data: { "Named": shun, "Shunqi": Zhu, "state": 2 },
                    success: function (e) {
                        if (e.length > 0) {
                            $(x.target).css({ "background": "#ffffff" })
                            createSel(e);
                        } else {
                            $(x.target).css({ "background": "red" })
                        }
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            }
            function createSel(e) {
                $("#seleect_codes option").remove();
                var gui;
                var leix;
                var liao;
                var ji;
                var Sone ="";
                var SDET ="";
                var Nyleds ="";
                $.each(e, function (i, item) {
                    $("#seleect_codes").append(`<option value="${item.FM_name}">${item.FM_name}</option>`);
                    leix = item.FM_Zhuang
                    ji = item.FM_ji
                    gui = item.FM_gg
                    Sone = item.FM_yj == "纸制品" ? "纸质" : item.FM_yj == "木制品" ? "木质" : item.FM_yj == "塑料制品" || item.FM_ej == "胶带" ? "塑料" :item.FM_yj;
                    SDET = item.FM_ej
                    Nyleds = item.FM_nyl
                })
                $(x.target).parent().parent().children().eq(4).children().first().val(e[0].FM_name)
                $(x.target).parent().parent().children().eq(5).children().first().val(gui)
                $(x.target).parent().parent().children().eq(7).children().first().val(ji)
                $(x.target).parent().parent().children().eq(6).children().first().val(Nyleds)
                $(x.target).parent().parent().children().eq(11).children().first().val(leix)
                $(x.target).parent().parent().children().eq(8).children().first().val(Sone)
                $(x.target).parent().parent().children().eq(9).children().first().val(SDET)
            }
        })
        //点击上传打开文件
        $(function () {
            $("#ShangC").click(function () {
                $(".YCFile").toggle()
            })
            $("#TIjaio").click(function () {
                var fileUpload = $('#SHanngcF')[0];
                if (fileUpload.files.length > 0) {
                    var formData = new FormData();
                    formData.append('file', fileUpload.files[0]);

                    $.ajax({
                        url: '/Material/ExcelFilePath',
                        type: 'POST',
                        data: formData,
                        processData: false,		//用于对data参数进行序列化处理 这里必须false
                        contentType: false,
                        success: function (fgggh) {
                            if (fgggh.length == 0) {
                                alert("该文件已打开，请关闭后重试！")
                            } else {
                                CreateBom(fgggh)
                                $(".YCFile").hide()
                            }
                        },
                        error: function (xhr) {
                            alert("系统错误" + xhr);
                        }
                    })
                } else {
                    alert('请选择要上传的文件！');
                }
            })

            function CreateBom(fgggh) {
                console.log(fgggh)
                $("#WLTable tr").remove();
                $.each(fgggh, function (i, item) {
                    //var KKOL = ""
                    var Sone = item.BOM2_Sone;
                    Sone = Sone == "纸制品" || Sone == "纸质" ? "1" : Sone == "木制品"||Sone == "木质" ? "2" : Sone == "塑料制品" || Sone == "塑料" ? "3" : Sone == "金属制品" ? "4" : Sone == "布" ? "5" : Sone == "胶粘制品" ? "6" : Sone == "其他" ? "7" : Sone == "套件" ? "8" : Sone;
                    var GUIG = item.FM_long + "*" + item.FM_kuan + "*" + item.FM_gao
                    $.ajax({
                        url: '/Admin/Purchasing_Authority',
                        type: 'GET',
                        data: { "id": Sone, "state": 4 },
                        success: function (data) {
                           /* KKOL = "<select id='leib_ji' class='inwei'>"
                            $.each(data, function (i, item) {
                                KKOL += "<option value='" + item.zl_name + "'>" + item.zl_name + "</option>"
                            })
                            KKOL += "</select>"
*/
                    var $tr =$(`<tr id="WLtr">
                               <td style="width:20px;"><input type="checkbox" class="XANZK"/></td>
                               <td><lable id="labes">${item.BOM2_chen}</lable></td>
                               <td><a id="app_CkWl" href="#">物料信息</a></td>
                               <td ><input type="text" class="inwei" name="empLiao" id="empLiao" value="${item.BOM2_liao}" /></td>
                               <td style="width: 200px;"><input type="text" class="inwei" name="empName" id="empName" value="${item.BOM2_wuLiu}" readonly/></td>
                               <td ><input type="text" class="inwei" name="empMiao" id="empMiao" value="${GUIG}" /></td>
                               <td ><input type="number" class="inwei" name="empNian" min="0" max="1000000" value="${item.BOM2_Nian}" /></td>
                               <td>
                                   <input type="text" id="txtxun" class="inwei" name="CL_name" list="select_codes" value="${item.BOM2_fenzi}" />
                                   <datalist id="select_codes" class="form-control" style="display:none" >
                                        @foreach (var item in ViewBag.JIliang as List<Freht>)
                                                   {
                                                    <option>@item.Fre_beizhu</option>
                                                   }
                                   </datalist>
                               </td>
                               <td >
                                <input type="text" class="inwei" id="leibie" min="0" max="1000000" value="${Sone}" />
                               </td>
                               <td id="jisndd">
                                   <input type="text" class="inwei" id='leib_ji' min="0" max="1000000" value="${item.BOM2_ST}" />
                               </td>
                               <td id="B_MS"><input type="number" class="inwei" name="empYong" value="${item.BOM2_Yong}" readonly style="text-align:center;background-color:#f4eef0;" /></td>
                               <td>
                                   <input type="text" id="txtxuns" class="inwei" name="CL_Gong" list="select_Lei"  value="${item.BOM2_Lei}"/>
                                   <datalist id="select_Lei" class="form-control" style="display:none" >
                                       <option>--@Resource.String63--</option>
                                       <option value="外购">@Resource.String130</option>
                                       <option value="自制">@Resource.String131</option>
                                   </datalist>
                               </td>
                               <td style="display:none">1</td>
                               <td style="display:none">${item.BOM2_id}</td>
                           </tr>`
                        );
                    $('#WLTable').append($tr);
                    //        $("#WLTable").children().last().children().eq(8).children().val(Sone)
                    //$("#WLTable").children().last().children().eq(9).children().val(item.BOM2_ST)

                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })

                })
            }
        })

        //设计主管分配人员和审核
        $(function () {
            $(document).on("click", "#WT_JDR_TJ", function (e) {
                receiver($(e.target))
            })
            $(document).on("click", "#TJIAO_JDRF", function () {
                if (confirm("人员分配只能分配一次请谨慎选择,若使用未分配的账号继续上传会跳过不处理")) {
                    SJ_BEIZ()
                }
            })
            //通过设计图
            $(document).on("click", "#WT_pass", function (e) {
                Through_drawing($(e.target))
            })

            //点击驳回设计图
            $(document).on("click", "#WT_qdbh", function () {
                Rejected_plan()
                $("#WT_dh_mb").css({ "display": "none" })
            })

            //完成设计委托
            $(document).on("click", "#btnWANC", function () {
                if (confirm("是否完成此项目")) {
                    complete_plan()
                }

            })

            //点击打开驳回面板驳回到业务
            $(document).on("click", "#btnBOHUI", function (e) {
                $("#WT_dh_mb2").css({ "display": "block" })
                var num = $("#Login_N").text()
                $("#WT_dhr2").text(num)
            })

            //点击关闭驳回面板
            $(document).on("click", "#WT_qxbh2", function (e) {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WT_dhly2").val("")
                $("#WT_dhr2").text("")
            })

            //点击驳回到业务 根据身份进行判断
            $(document).on("click", "#WT_qdbh2", function (e) {
                $("#WT_dh_mb2").css({ "display": "none" })
                var shen = $("#Login_sf").text()
                if (shen == "设计员") {
                    append_Contracts20()
                } else if (shen == "设计主管") {
                    var zhuang = "1"
                    append_Contracts2(zhuang)
                } else if ($("#Login_bm").text() =="业务") {
                    append_Contr()
                }
                window.location.href = "/Contracts/Inspect_Contracts"
            })
            //设计完成业务判断是否通过
            function append_Contr() {
                var name = $("#Login_N").text()
                var BZJG = [];
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var time = year + "/" + month + "/" + date
                var bian = $("#txtdan").val()
                BZJG.push({
                    Fr_fl: "设计委托",//待处理模块
                    De_tiji: "业务员有异议",//待处理内容
                    Cl_juli: "设计主管",//接收人
                    Nd_jiage: name,//发起人
                    Fr_zhuang: "待处理",//装态
                    Fr_time: time,
                    Fr_bian: bian
                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                var bcxx = {
                    D_Ton: $('#WT_rwdh').text(),
                    D_dhly: $("#WT_dhly2").val(),
                    D_dhr: $("#WT_dhr2").text()
                };
                $.ajax({
                    url: "/Application/Bohuus",
                    type: 'POST',
                    data: { "shunnf": $("#txtdan").val(), "dsres": bcxx },
                    success: function (text) {
                        if (text == "1") {
                            alert("单据没有设计！")
                        } else if (text == "3") {
                            alert("驳回失败！")
                        } else {
                            $.ajax({
                                url: "/Contracts/Addfr",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert("已返回对应的发起人账号")
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })
                        }
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }
            //设计驳回代办
            function Bohuis() {
                var mbr = $("#Faqiren").text()
                var name = $("#Login_N").text()
                var BZJG = [];
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var time = year + "/" + month + "/" + date
                var bian = $("#txtdan").val()
                BZJG.push({
                    Fr_fl: "设计委托",//待处理模块
                    De_tiji: "设计主管驳回单据",//待处理内容
                    Cl_juli: mbr,//接收人
                    Nd_jiage: name,//发起人
                    Fr_zhuang: "待处理",//装态
                    Fr_time: time,
                    Fr_bian: bian
                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Contracts/Addfr",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        alert("已返回对应的发起人账号")
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }
            //点击打开驳回面板
            $(document).on("click", "#log_back", function (e) {
                var id = $(e.target).parent().parent().children().first().text()
                var name = $(e.target).parent().parent().children().eq(4).text()
                $("#WJ_ID").text(id)
                $("#WT_dh_mb").css({ "display": "block" })
                var num = $("#Login_N").text()
                $("#WT_dhr").text(num)
                $("#WJ_tjr").text(name)
            })
            //点击关闭驳回面板
            $(document).on("click", "#WT_qxbh", function (e) {
                $("#WT_dh_mb").css({ "display": "none" })
                $("#WT_dhly").val("")
                $("#WT_dhr").text("")
                $("#WJ_ID").text("")
                $("#WJ_tjr").text("")
            })
            //完成上传任务
            $(document).on("click", "#WCSJ", function () {
                var temp1 = 0
                var temp2 = 0
                $("#div3__tb tr").each(function (i, item) {
                    var name = $(item).children().eq(5).text()
                    var zhuang = $(item).children().eq(7).text()

                    if (name == $("#Login_N").text()) {
                        temp1+=1
                    }
                    if (zhuang == "驳回") {
                        temp2+=1
                    }
                    console.log(temp1, temp2)
                })
                console.log(temp1, temp2)
                if (temp1 > 0 && temp2 == 0) {
                    if (confirm("是否上传全部文件，若未全部上传请点击取消，")) {
                        var BZJG = [];
                        BZJG.push({
                            SJR_id: $("#Login_name").text(),
                            SJ_Bian: $("#txtdan").val(),
                            SJ_ZT: "完成"
                        })
                        $.ajax({
                            url: "/Contracts/chaneSJBZ",
                            type: 'POST',
                            data: JSON.stringify(BZJG),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (text) {
                                console.log(text)
                                BohuIIis()
                            },
                            error: function (text) {
                                alert("系统错误" + text);
                            }
                        })
                    }
                }
                else {
                    alert("还未上传附件或上传文件中有被驳回附件未处理")
                }
            })
            //设计驳回代办
            function BohuIIis() {
                var name = $("#Login_N").text()
                var BZJG = [];
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var time = year + "/" + month + "/" + date
                var bian = $("#txtdan").val()
                BZJG.push({
                    Fr_fl: "设计委托",//待处理模块
                    De_tiji: "设计员已上传图纸",//待处理内容
                    Cl_juli: "设计主管",//接收人
                    Nd_jiage: name,//发起人
                    Fr_zhuang: "待处理",//装态
                    Fr_time: time,
                    Fr_bian: bian
                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Contracts/Addfr",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        alert("已提交设计主管处")
                        window.location.href = "/Contracts/Inspect_Contracts"
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }
            //获取分配人
            function getFPR() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "App_ban": $('#txtdan').text(), "state": 14 },
                    success: function (e) {
                        $("#WT_JDR_Tb tr").remove()
                        $.each(e, function (i, item) {
                            var $tr =
                                $(`
                                    <tr style="background-color:white;text-align:center">
                                        <td>
                                            <select id="WT_JDR_se" class="WT_JDR_a2" value="${item.Dengli.DE_nae}">
                                            <option value="">——@Resource.String711——</option>
                                                @foreach (var item in ViewBag.res as List <LanDBom.Models.Dengli>)
                                                 {
                                                    if (item.DE_bumeng==2)
                                                    {
                                                        <option value="@item.DE_phone+@item.DE_nae+@item.DE_ID">@item.DE_nae</option>
                                                    }

                                                 }
                                            </select>
                                        </td>
                                        <td>@Resource.String732</td>
                                        <td>${item.Dengli.DE_phone}</td>
                                        <td><input  type="text" value="${item.SJ_ZT}"/></td>
                                        <td><a href="#" id="WT_JDR_TJ">@Resource.String733</a></td>
                                    </tr>
                                `)
                            $("#WT_JDR_Tb").append($tr)
                        })
                    },
                    error: function () {
                        alert("系统错误！");
                    }
                })
            }

            function complete_plan() {
                var index = 0
                $(".sjtzt").each(function (i, item) {
                    if ($(item).text() != "设计主管通过") {
                        index += 1
                    }
                })
                if (index == 0) {
                    var RZ_bian = $("#txtdan").val()
                    var BZJG = [];
                    BZJG.push({
                        D_Ton: RZ_bian,
                        D_zhuang: "4"
                    })
                    console.log("共" + BZJG.length + "数据");
                    console.log(BZJG);
                    $.ajax({
                        url: "/Contracts/Modify_des_zhuang",
                        type: 'POST',
                        data: JSON.stringify(BZJG),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            alert(text)
                            var now = new Date($.now());
                            var year = (now.getFullYear()).toString();
                            var month = (now.getMonth() + 1).toString();
                            var date = (now.getDate()).toString();
                            var time = year + "/" + month + "/" + date
                            var bian = $("#txtdan").val()
                            var mbr = $("#Faqiren").text()
                            var name = $("#Login_N").text()
                            var BZJG = [];
                            BZJG.push({
                                Fr_fl: "设计委托",//待处理模块
                                De_tiji: "设计委托完成",//待处理内容
                                Cl_juli: mbr,//接收人
                                Nd_jiage: name,//发起人
                                Fr_zhuang: "待处理",//装态
                                Fr_time: time,
                                Fr_bian: bian
                            })
                            console.log("共" + BZJG.length + "数据");
                            console.log(BZJG);
                            $.ajax({
                                url: "/Contracts/Addfr",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert("已提交至单据发起人")
                                    Load_design_table2()
                                    window.location.href = "/Contracts/Inspect_Contracts"
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })

                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }

                    })
                }
                else {
                    alert("还有" + index+"条设计图没有通过审核")
                }
            }

            function Rejected_plan() {
                var de_id = $("#WJ_ID").text()
                var bhly = $("#WT_dhly").val()
                var shr = $("#WT_dhr").text()
                if (bhly == "") {
                    alert("请输入驳回理由")
                }
                else {
                    var BZJG = [];
                    BZJG.push({
                        DE_id: de_id,
                        DE_JDR: shr,
                        DE_wenjain: bhly,
                        DE_tuiLei: "驳回"

                    })
                    console.log("共" + BZJG.length + "数据");
                    console.log(BZJG);
                    $.ajax({
                        url: "/Contracts/Modify_INF_zhuang",
                        type: 'POST',
                        data: JSON.stringify(BZJG),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            alert(text)
                            var mbr = $("#WJ_tjr").text()
                            var name = $("#Login_N").text()
                            var BZJG = [];
                            var now = new Date($.now());
                            var year = (now.getFullYear()).toString();
                            var month = (now.getMonth() + 1).toString();
                            var date = (now.getDate()).toString();
                            var time = year + "/" + month + "/" + date
                            var bian = $("#txtdan").val()

                            BZJG.push({
                                Fr_fl: "设计委托",//待处理模块
                                De_tiji: "设计图被驳回",//待处理内容
                                Cl_juli: mbr,//接收人
                                Nd_jiage: name,//发起人
                                Fr_zhuang: "待处理",//装态
                                Fr_time: time,
                                Fr_bian: bian

                            })
                            console.log("共" + BZJG.length + "数据");
                            console.log(BZJG);
                            $.ajax({
                                url: "/Contracts/Addfr",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert("已驳回到指定人员")

                                    $("#WT_dh_mb").css({ "display": "none" })
                                    Load_design_table()
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })
                }
            }

            //通过设计图
            function Through_drawing(e) {
                DE_id = e.parent().parent().children().first().text()
                var num = $("#Login_N").text()
                var BZJG = [];
                BZJG.push({
                    DE_id: DE_id,
                    DE_JDR: num,
                    DE_tuiLei: "通过"

                })
                console.log("共" + BZJG.length + "数据");
                console.log(BZJG);
                $.ajax({
                    url: "/Contracts/Modify_INF_zhuang2",
                    type: 'POST',
                    data: JSON.stringify(BZJG),
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    success: function (text) {
                        alert("审核通过")
                        Load_design_table()
                        //location.reload(true)
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })
            }
            //分配接单人的方法
            function receiver(e) {
                var index = e.text()
                if (index == "添加") {
                    var $tr = $(`
                    <tr style="background-color:white;text-align:center">
                        <td>
                            <select id="WT_JDR_se" class="WT_JDR_a2">
                            <option value="">——@Resource.String711——</option>
                                @foreach (var item in ViewBag.res as List <LanDBom.Models.Dengli>)
                                 {
                                    if (item.DE_bumeng==2)
                                    {
                                        <option value="@item.DE_phone+@item.DE_nae+@item.DE_ID">@item.DE_nae</option>
                                    }

                                 }
                            </select>
                        </td>
                        <td>@Resource.String732</td>
                        <td></td>
                        <td><input  type="text"/></td>
                        <td><a href="#" id="WT_JDR_TJ">@Resource.String733</a></td>
                    </tr>
                    `)
                    $("#WT_JDR_Tb").append($tr)
                }
                else {
                    e.parent().parent().remove()
                }
            }
            //提交接单人的方法
            function SJ_BEIZ() {
                var XMBZ = []
                var name = $("#Login_N").text()
                var BZJG = [];
                $(".WT_JDR_a2").each(function (i, item) {
                    var index = $(item).val()
                    var temp = index.split("+")
                    var lastElement = temp[2];
                    var TwoElement = temp[1];
                    var bz = $(item).parent().next().next().next().children().first().val()
                    var now = new Date($.now());
                    var year = (now.getFullYear()).toString();
                    var month = (now.getMonth() + 1).toString();
                    var date = (now.getDate()).toString();
                    var time = year + "/" + month + "/" + date
                    var bian = $("#txtdan").val()
                    XMBZ.push({
                        SJR_id: lastElement,//接单人id
                        SJ_BZ: bz,//备注
                        SJ_Bian: $("#WT_rwdh").text(),//申请单号
                        SJ_ZT:"未确定"
                    })
                    BZJG.push({
                        Fr_fl: "设计委托",//待处理模块
                        De_tiji: "设计主管分配的设计任务",//待处理内容
                        Cl_juli: TwoElement,//接收人
                        Nd_jiage: name,//发起人
                        Fr_zhuang: "待处理",//装态
                        Fr_time: time,
                        Fr_bian: bian
                    })
                })
                console.log("共" + BZJG.length + "数据", "共" + XMBZ.length + "数据");
                console.log(XMBZ);
                console.log(BZJG);
                if (XMBZ.length > 0) {
                    $.ajax({
                        url: "/Contracts/ADDSJBZ",
                        type: "POST",
                        data: JSON.stringify(XMBZ),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            $("#WT_JDR_TJ,#TJIAO_JDRF").css({ "display": "none" })
                            changeDes_sqshr()
                            getFPR()
                            alert(text)
                            $.ajax({
                                url: "/Contracts/Addfr",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert("已返回对应的发起人账号")
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })
                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })
                }
            }
            function changeDes_sqshr() {
                var bcxx = {
                    D_Ton: $('#WT_rwdh').text(),
                    D_AppRevi: $("#Login_N").text(),
                };
                //---------------------------------------------------------------新增功能
                console.log(bcxx)
                $.ajax({
                    url: "/Contracts/Temporary_storage3",
                    type: "POST",
                    data: bcxx,
                    success: function (data) {

                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })

            }

            function append_Contracts2(zhuang) {
                var bcxx = {
                    D_Ton: $('#WT_rwdh').text(),
                    D_dhly: $("#WT_dhly2").val(),
                    D_dhr: $("#WT_dhr2").text(),
                    D_zhuang: zhuang,
                };
                //---------------------------------------------------------------新增功能
                console.log(bcxx)
                $.ajax({
                    url: "/Contracts/Temporary_storage2",
                    type: "POST",
                    data: bcxx,
                    success: function (data) {
                        changeAPP_BOhui()
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            }
            //设计员驳回值设计主管分配工作  人员不变可更改备注
            function append_Contracts20() {
                var shun=2
                var Ton = $("#txtdan").val()
                //---------------------------------------------------------------新增功能
                $.ajax({
                    url: "/Contracts/Append_Contracts20",
                    type: "POST",
                    data: { "Shun": shun, "Ton": Ton },
                    success: function (data) {
                        var name = $("#Login_N").text()
                        var BZJG = [];
                        var now = new Date($.now());
                        var year = (now.getFullYear()).toString();
                        var month = (now.getMonth() + 1).toString();
                        var date = (now.getDate()).toString();
                        var time = year + "/" + month + "/" + date
                        var bian = $("#txtdan").val()
                        BZJG.push({
                            Fr_fl: "设计委托",//待处理模块
                            De_tiji: "设计人员有异议",//待处理内容
                            Cl_juli: "设计主管",//接收人
                            Nd_jiage: name,//发起人
                            Fr_zhuang: "待处理",//装态
                            Fr_time: time,
                            Fr_bian: bian

                        })
                        console.log("共" + BZJG.length + "数据");
                        console.log(BZJG);
                        $.ajax({
                            url: "/Contracts/Addfr",
                            type: 'POST',
                            data: JSON.stringify(BZJG),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (text) {
                                alert("已驳回到设计主管")
                                window.location.href = "/Contracts/Inspect_Contracts"
                            },
                            error: function (text) {
                                alert("系统错误" + text);
                            }
                        })
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            }
            function changeAPP_BOhui() {
                var bcxx = {
                    AP_bian: $('#txtdan').val(),
                    APP_liy: $("#WT_dhly2").val(),
                    APP_shr: $("#WT_dhr2").text(),
                    App_zhuang:"驳回"

                };
                //---------------------------------------------------------------新增功能
                console.log(bcxx)
                $.ajax({
                    url: "/Contracts/changeAPP_BOhui",
                    type: "POST",
                    data: bcxx,
                    success: function (data) {
                        Bohuis()
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            }

            $(document).on("click", "#ckbhly_tz", function (e) {
                $("#WT_dh_mb3").css({ "display": "block" })
                id = $(e.target).parent().parent().children().eq(0).text()
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 17, "id": id },
                    success: function (path) {
                        $.each(path, function (i, item) {
                            $("#WT_dhly3").val(item.DE_wenjain)
                            $("#WT_dhr3").text(item.DE_JDR)
                        })
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            })

            //点击关闭驳回面板
            $(document).on("click", "#WT_qxbh3", function (e) {
                $("#WT_dh_mb3").css({ "display": "none" })
                $("#WT_dhly3").val("")
                $("#WT_dhr3").text("")
            })
        })

    </script>

}